In my below code, I am trying to pass the global value of my PHP variable "z" in the ajax_processor.php file.
However Its not working as it doesn't picking up the value from my php code in the body(Code shown at the last)
Could someone please help me on this. I am trying this code to implement a facebook type auto load content on scroll event.
<head>
<script type="text/javascript">
$(document).ready(function(){
$.ajaxSetup({cache: false}); // disabling cache, omit if u dont need
var defaultBtnText = "<span class='pseudolink'>Load More Content</span>";
var buttonLoadingText = "<img src='images/loader.gif' alt='' /> Loading..";
$(document).scroll(function(){
if ($(window).scrollTop() + $(window).height() >= $(document).height())
{
loadMore();
}
});
$("#loadButton").click(function(){
loadMore();
});
function loadMore()
{ alert ('<?php echo $z; ?>');
$("#loadButton").html(buttonLoadingText);
$.ajax({
url: 'ajax_processor.php?global1=<?php echo $z; ?>',
method: 'get',
success: function(data){
$("#tab1_content1").append(data);
$("#loadButton").html(defaultBtnText);
}
});
}
});
</script>
</head>
Below is the part of my asked code in <body>
<body>
<?php
$query=("SELECT * FROM tbl_content");
$result=mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$window = $row['id'];
$window = $row['title'];
$window = $row['description'];
echo "<h2>".$row['id']." ".$row['title']."</h2>";
echo "<p>".$row['description']."</p>";
$GLOBALS['z']=$row['id'];
echo "<h2>".$z."</h2>";
}
?>
</body>