$.ajax({
dataType : "html" ,
url: "jquery-loadMoreComments.php?lastComment="+ $(".postedComment:last").attr('id')&"section="+'.$sid.',
success: function(html) {
I am having this ajax request from one file to other and I am retrieving the url variable in other file like this
$filtered = filter_input(INPUT_GET, "lastComment", FILTER_SANITIZE_URL);
$filtered1 = filter_input(INPUT_GET, "section", FILTER_SANITIZE_URL);
The first variable gets retrieved properly but the second variable is not getting to the other file. And $sid is retrieved by the first file from the url and then is sent via ajax to the second file to continue the request.
I changed the url to this
url: "jquery-loadMoreComments.php?lastComment="+ $(".postedComment:last").attr('id'),section: '<?= $sid ; ?>',
then in the second php file to retrieve the $sid I have written this
$filtered = filter_input(INPUT_GET, "section", FILTER_SANITIZE_URL);
but still it is not executing . I think the $sid variable is not passed properly. In the first php file I have not written any code to pass the variabl $sid, how can I do that.
I suspect the problem is with
'.$sid'at the end of the URL. You’re probably expecting that to be replaced with the PHP variable, but this doesn’t look like a context where replacement happens.To make the replacement happen, you need to get back into PHP processing mode, e.g.
Also, rather than constructing the URL parameters by concatenating strings, use the
data:parameter to$.ajaxand supply an object. jQuery will construct the parameter string automatically for you, with proper URL-encoding. So it should be: