Reputation: 235
So I have this code :
function checkStatus()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if (xmlhttp.responseText == "1") {
document.getElementById("maincontent").innerHTML = '<br/><br/><center>Please refresh the page to continue.</b></center>';
}
}
}
xmlhttp.open("GET","file.php?id=1",true);
xmlhttp.send();
}
and I'm wondering about the last 2 lines (xmlhttp.open and xmlhttp.send) , what is the function of these ? also when i go to file file.php?id=1 using the browser it only displays "0" whereas the the general function of the code is to redirect me to a website after i do a specific action and i believe the data is stored on file.php?id=1 but how can i see it from browser ? Note: I'm not HTML/PHP programmer but i recognize the basics
Upvotes: 0
Views: 125
Reputation: 13608
The lines before xmlhttp.open()
just create the XMLHttpRequest
object that will handle the AJAX connection. Calling xmlhttp.open()
is necessary to actually open the connection and xmlhttp.send()
to send the request. Only after the request is sent, a response can be received and handled by the onreadystatechange
handler.
This code looks rather obsolete, however. I would recommend not using XMLHttpRequest
directly but rather use a library for it - see jQuery, for example.
Upvotes: 1