Javascript Code:
var httprequest = new XMLHttpRequest();
var time = new Date();
if (httprequest) {
httprequest.onreadystatechange = function () {
if (httprequest.readyState == 4) {
alert("OK");
}
};
httprequest.open("GET", "http://www.google.com", false);
httprequest.send(null);
}
alert(new Date() - time);
IE8: OK,time dialog will be prompt
Chrome10: OK dialog prompted, but time dialog do not be prompt
Firefox3.6: OK, time dialog will not be prompt
Why some dialog not to be prompt?
httprequest.send(null) in your case doesn’t return at all – it blocks js code execution, so anything after that line doesn’t get executed – I can’t tell you why it does that, it might be specifics of implementation on a particular browser or something else.
What you want to do here is to run it asynchronously: change “false” to “true” when calling “open” method:
On a related note – if you are to start playing with ajax, try some javascript framework like jQuery – they do a great job of making your life easier as a js developer providing browser-neutral methods for dealing with DOM, events, ajax and more.