I am working on project that when someone scrolls the page down, it loads more items. The problem is when I use jquery to send two values via get in the url, it does not work.Wwhen items load then they do not work properly because php is not getting any value via jquery. My code is:
$(document).ready(function(){
function last_msg_funtionc()
{
var ID=$(".productsc:last").attr("id");
var CID=$(".productsc").attr("cid");
$.post("categories.php?action=get&last_msg_id=+ID&cid="+CID,
function(data){
if (data != "") {
$(".productsc:last").after(data);
}
$('div#last_msg_loader').empty();
});
};
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
last_msg_funtionc();
}
});
});
And when I send a single value this 'last_msg_id' it works fine. What am I doing wrong? my php code is
<?php
require_once'config.php';
$last_msg_id=$_POST['last_msg_id'];
$action=$_POST['action'];
if($action <> "get")
{
include_once'categories_first.php';
}
else
{
include'categories_second.php';
}
amd categorys_first.php is not need to conect with jquery . jquerye get last id from categories_first.php. and now this is categories_second.php jquery send cid to this file code is
$last_msg_id=$_GET['last_msg_id'];
$get_item=mysql_query('select * from items where cid="'.$_GET['cid'].'" and id < "'.$last_msg_id.'" order by id desc limit 4');
$last_msg_id='';
//another code here
Here is your code which has been updated
$.post("categories.php?action=get&last_msg_id="+ID+"&cid="+CID,
Here is how you should be doing this since you are not POSTing
$.get('categories.php', {'action':'get','last_msg_id':ID,'cid':CID}, function(data){ // your code });
Use .get()
since you're not actually sending any values through $_POST
var ID=$(".productsc:last").attr("id");
var CID=$(".productsc").attr("cid");
$.get("categories.php",
{
action: 'get',
last_msg_id: ID,
cid: CID
},
function(data){
if (data != "") {
$(".productsc:last").after(data);
}
$('div#last_msg_loader').empty();
});
correct line:
$.post("categories.php?action=get&last_msg_id="+ID+"&cid="+CID,
At a glance it looks like the ID var isn't outside of the quoted statement:
"categories.php?action=get&last_msg_id=+ID&cid="+CID
Try this: "categories.php?action=get&last_msg_id=" +ID +"&cid="+CID