Forum Moderators: open

Message Too Old, No Replies

xmlhttprequest.open doesn't work in firefox

         

welkin25

2:04 am on Jun 14, 2007 (gmt 0)

10+ Year Member



hi,

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!

Drag_Racer

3:30 am on Jun 14, 2007 (gmt 0)

10+ Year Member



here is the code I use for requests.

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.

colandy

8:24 am on Jun 14, 2007 (gmt 0)

10+ Year Member



Run test.asp on it's own and ensure it displays/returns something.

I use PHP and find that if my PHP page doesn't display anything the AJAX just sits and waits.

welkin25

3:49 pm on Jun 14, 2007 (gmt 0)

10+ Year Member



Thanks everyone for the help. I found that the reason is the page running the ajax script was not placed in my localhost directory, and Firefox disables fetch requests from other servers.

Here's an article I found with more details on Firefox and xmlhttprequest:

[xml.com...]