grenz grenz - 2 years ago 154
PHP Question

How to string PHP to URL on Javascript

My code:

var page = 1;
$(window).scroll(function () {
$('#more').hide();
$('#no-more').hide();
if($(window).scrollTop() + $(window).height() > $(document).height() - 200) {
$('#more').css("top","400");
$('#more').show();
}
if($(window).scrollTop() + $(window).height() == $(document).height()) {
$('#more').hide();
$('#no-more').hide();
page++;
var data = {
page_num: page
};
var actual_count = "<?php echo $actual_row_count; ?>";
if((page-1)* 2 > actual_count){
$('#no-more').css("top","400");
$('#no-more').show();
}else{
$.ajax({
type: "POST",
url: "search-data.php/?search=<?php echo $search ?>", // <---- Here Problem
data:data,
success: function(res) {
$("#result").append(res);
console.log(res);
}
});
}
}
});


on the file
search-data.php
:

$search = $_GET['search']; // no string

Answer Source

Change your ajax request to GET

$.ajax({
    type: "GET",
    url: "search-data.php/?search=<?php echo $search ?>",
    data:data,
    success: function(res) {
        $("#result").append(res);
        console.log(res);
    }
});

Thanks for your answer "Morteza"

 $.ajax({
       type: "GET",
       url: "search-data.php/?search=<?php echo $_GET['search'] ?>&page=+data.page_num",
       data:data,
       success: function(res) {
       $("#result").append(res);
       console.log(res);
                        }
                    });

Thankyou very much :D

Regard's

Grenz

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download