I'm trying to retrieve information from a PHP page which queries a database based on the ?id= parameter given. Doing so via AJAX should give the user information on the specific item etc. If the id parameter does not exist within the database, the user will be redirected to the lookup page.
When looking at AJAX examples and following the same steps it would seem that the parameter isn't being used for the MySQL query - it's using the header information to redirect me and retrieve the lookup page as if an incorrect value was given however the ID exists.
Any ideas on what's going wrong?
var id = $('#code').val; is the input where users supply the ID they wish to lookup.
$(document).ready(function() {
$('#check').click(function() {
var id = $('#code').val;
if (id=="")
{
document.getElementById("result").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","result.php?id="+id,true);
xmlhttp.send();
});
});