Click to See Complete Forum and Search --> : XMLHTTPRequest in Firefox


marcowatty2000
11-24-2008, 04:54 AM
Hi all,

I'm trying to get a XMLHTTPRequest to work and it does in IE but not in firefox. My call is as follows:


function getXmlHttpRequestObject()
{
if (XMLHttpRequest) {
return new XMLHttpRequest(); //Not IE
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP"); //IE
} else {
alert("Your browser doesn't want to use AJAX");
}
}


I've looked on the web and on webdeveloper.com, but none of the suggestions have solved my problem.

I'm making a call from one server to another, does this cause problems for Firefox?

Can anyone help?

Many thanks.

rpgfan3233
11-24-2008, 05:45 AM
That should have worked...

Make sure that it actually isn't creating a request:
<body onload="alert(getXmlHttpRequestObject());">

If that displays "[object XMLHttpRequest]", then obviously it's working, and another part of your code is failing.

marcowatty2000
11-24-2008, 06:26 AM
Cheers for the quick reply rpgfan.

I tried that and it is displaying "[object XMLHttpRequest]" as you say. So i'll attach another snippet of my code which could be causing the problem, in the hope that someone can see the cause (as i can't!)


var receiveReq = getXmlHttpRequestObject();
function SFXReturn(datafile) {
document.getElementById("div1").innerHTML = "<img src=http://www.myurl.com/spinner.gif> loading...";
if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
{
receiveReq.open("get", datafile, true);
receiveReq.onreadystatechange = handleSFXReturn;
receiveReq.send(null);
}
}
function handleSFXReturn() { //Called every time the XmlHttpRequest state changes.
if (receiveReq.readyState == 4) { //Check to see if it is finished, 4 indicates it has.
var xmlDocument = receiveReq.responseXML; //Response is XML not Text

rpgfan3233
11-24-2008, 07:52 AM
Have you checked the Error Console in Firefox (`Tools' menu)? My first thought is that responseXML is null because the MIME type isn't set to an XML type like text/xml or application/xml. As a result, any attempts to access it as an XML document will fail. Try adding an alert(xmlDocument) after the last line in that code snippit you posted above.

\\.\
11-24-2008, 08:42 AM
try the other response types like responseBody and responseText and see if any of them contain the data your expecting.