The Photo.php file is expected to show a message.
But when I add ?page=2 to address it doesn’t call Photos function to open the Photo.php file.
function Photos() {
var opt = <?php echo $_GET['page'];?>
alert(opt);
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("Results").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","Photo.php?page="+opt,true);
xmlhttp.send();
}
function showCat(option){
....
}
<?php
if(isset($_GET['page'])){
echo '<script type="text/javascript">'
,'myPhotos();'
, '</script>';
}
echo 'Results go here';
?>
photo.php
if(isset($_GET["page"])){
echo "photo";
}
As Akam noticed; you forgot to put quotes around the string variable:
Should be:
This should have cased a JavaScript error that could have been noticed in the console of Firebug. Firebug is a very handy plugin to work out JavaScript or network problems. In the console you can find xmlhttpreqest with request and response headers as well as JavaScript errors and if you need to see details of JavaScript objects you can console.log(myObject) to the console where it can be clicked on to show more details.
I’m not sure if chrome has the same features but if you don’t have Firefox or just like Chrome better then pressing F12 will open developer tools, same as in Opera and Internet explorer although I personally prefer Firefox with firebug plugin.