I'm having trouble with some basic AJAX, I'm very new to it but have found a similar chunk of javascript that I've altered to my needs (kind of).
I have a <div> that I want to change upon the click of a link. It contains a list of entries, ordered by some variable $order. I want clicking the "least" or "most" button to change that order.
The <div> is called "content"
Here's the JS:
<!--
function update(str){
var xmlhttp;
if (str==""){
document.getElementById("content").innerHTML="";
return;
}
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("content").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/site/linkfilter.php?order="+str,true);
xmlhttp.send();
}
-->
The physical link works and triggers the above code, with "str" being either "most" or "least", but it never seems to actually access the linkfilter.php file, doesn't even trigger a simple "echo 'hello';" on the first line.
Have a feeling I'm using xmlhttp completely wrong.
And here's the only really relevant part of the linkfilter.php file (with an exit; at the end)
else{
$_SESSION['order']=$_GET['order'];
header("location:/browse/");
}
I have the content <div> set up to act differently depending on the order and if you think it necessary to see it, it's here: pinchweb
Any help would be greatly appreciated. I haven't got round to the task of actually learning JS yet but couldn't pass up on this opportunity for AJAX.