Forum Moderators: open
I just started learning ajax following the tutorial at [w3schools.com...] I copied the code, only modifying the url of time.asp as follows:
xmlHttp.open("GET","http://localhost/Test/time.asp",true);
xmlHttp.send(null);
This worked in IE, but somehow it didn't work in Firefox. If I insert alerts before and after xmlHttp.open, only the first alert will pop up, hence I think somehow it's not getting past the open statement (I'm a C programmer, so maybe this is not the right way to debug?). By inserting alerts around I know that xmlHttp=new XMLHttpRequest(); has succeeded. Does anyone have any idea why it doesn't work?
Thanks in advance!
function ajaxRequest(){
var URL = "http://localhost/Test/time.asp";
var container = document.getElementById("container_ID"); //destination of returned data
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
request.open("GET", URL, true);
request.onreadystatechange = function() {
if (request.readyState == 4) { // readyState, see below
container.innerHTML = request.responseText;
}
}
request.send(null);
}
now your 'container' has been populated with the returned response from the 'get' request.
this is just a basic example which will give you a place to start from. There is other functionality available, such as error checking, mime types, data formats, etc... so keep studying.
ready state meanings
-------------------------------------
0: uninitialized - open has not been called yet.
1: loading - send has not been called yet.
2: loaded - send has been called, but the response is not yet available.
3: interactive - The response is being downloaded, and the responseText property holds partial data.
4: completed - The response has been loaded and the request is completed.
Here's an article I found with more details on Firefox and xmlhttprequest:
[xml.com...]