$.ajax({
dataType : "html" ,
url: "jquery-loadMoreComments.php?lastComment="+ $(".postedComment:last").attr('id')&"section="+'.$sid.',
success: function(html) {
我从一个文件到另一个文件有这个ajax请求,我正在检索其他文件中的url变量
$filtered = filter_input(INPUT_GET, "lastComment", FILTER_SANITIZE_URL);
$filtered1 = filter_input(INPUT_GET, "section", FILTER_SANITIZE_URL);
第一个变量被正确检索但第二个变量没有到达另一个文件。并且来自URL的第一个文件检索$sid
,然后通过ajax将 url: "jquery-loadMoreComments.php?lastComment="+ $(".postedComment:last").attr('id'),section: '<?= $sid ; ?>',
发送到第二个文件以继续请求。
我将网址更改为
$sid
然后在第二个php文件中检索$filtered = filter_input(INPUT_GET, "section", FILTER_SANITIZE_URL);
我写了这个
$sid
但仍未执行。我认为$sid
变量未正确传递。在第一个php文件中,我没有编写任何代码来传递变量{{1}},我该怎么做。
答案 0 :(得分:1)
我怀疑问题出在网址末尾的'.$sid'
。您可能希望将其替换为PHP变量,但这看起来不像是替换发生的上下文。
要进行替换,您需要重新进入PHP处理模式,例如
"§ion=<?= $sid ?>",
此外,不是通过连接字符串来构造URL参数,而是使用data:
参数$.ajax
并提供一个对象。 jQuery将自动为您构造参数字符串,并使用正确的URL编码。所以它应该是:
$.ajax({
dataType : "html" ,
url: "jquery-loadMoreComments.php",
data: {
lastComment: $(".postedComment:last").attr("id"),
section: '<?= $sid ?>'
},
success: function(html) {