# Other Programming > AJAX >  AJAX does not work with FireFox

## Player1005

Hi guys,

i got a little problem. my ajax code doesn't work proper
with IE it works great, but with FF it doesn't at all.
for info: the php i call gives back text with the 'echo'-method. so no xml! but this should not be an issue.

here is my code.
the alerter "biste da?" i never saw with FF


var response = "blabla" ;

function ServerRequest(DBID)
{
sndReq(DBID);
}

function sndReq(DBID) {
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
http = new ActiveXObject("Microsoft.XMLHTTP");
}else{
http = new XMLHttpRequest();
http.overrideMimeType('text/xml');

}
http.open('GET', 'http://localhost/fillme.php?action=' + DBID, false);

alert(http.readyState );
http.onreadystatechange = handleResponse;
alert(http.readyState );
http.send(null);
}

function handleResponse()
{
alert("biste da?");
if(http.readyState == 4)
{
if (http.status == 200)
{
response = http.responseText;
if(response.indexOf('|' != -1))
{
response = response.split("|||");
response = response[1];
}
}
}
}


Thanx in advance for help!!
PL

----------


## mmetzger

AJAX should work fine with FireFox.  How are you accessing the website?  You need to make sure that your links are exactly the same as the address you initially type in (ie, http://localhost/ is different from http://127.0.0.1, etc.)

You can also enable the JavaScript Console to see if there's anything wrong.

----------


## Player1005

Hi,

I am accessing the site with localhost as well.
Since I am not a JS-Crack: where do I find that JS console?!?

Thx,
PL

----------


## Player1005

hhhmmm. strange.
I think i found the bug.
FireFox doesn't like it when I set the 'asyncron' state on 'false' to tell the script to wait for the reply of the serverrequest.

so instead of 
  http.open("GET", destURL, true);
I am using
  http.open("GET", destURL, false);

but I NEED that feature!
What can I do?

----------


## naimeshgalsar

for that u have to use the other code just use this code for the mozilla

<html>
<head>
<script type="text/javascript">
var xmlDoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("note.xml");
getmessage()
}
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load("note.xml");
xmlDoc.onload=getmessage
}
else
{
alert('Your browser cannot handle this script');
}
}function getmessage()
{
document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagName("to")[0].firstChild.nodeValue
document.getElementById("from").innerHTML=
xmlDoc.getElementsByTagName("from")[0].firstChild.nodeValue
document.getElementById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].firstChild.nodeValue
}
</script>
</head><body onload="loadXML()" bgcolor="yellow">
<h1>W3Schools Internal Note</h1>
<p><b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span>
<hr />
<b>Message:</b> <span id="message"></span>
</p>
</body>
</html>

----------


## varunvirtually

Hey specifying full paths for everything makes it work in IE, with partial paths, it works in netscape, opera, firefox.

Can we send an argument to the function which handles the HTTP request?
I had to change a dynamic variable, I got an alternative: 
1. Pass the name of the dynamic variable from HTML to Javascript as a string
2. In JS make a global variable and assign it the string containing name to that dynamic variable
3. Now in function u handle http request, use eval() to make Javascript code from the variable like eval(varname) = http.responseText

----------


## ddt999

Player1005, i started using Ajax end of last year, but have never had any problems with it working in FF, actually mine seems to work better in FF than in IE. I also never had to put the 'asyncron' state on 'false'

My ajax is in a seperate .js file: Will show how i did it, mayhaps it will help you in some way.

My php also sends back the text using the 'echo' method without any xml!



```

//create the object on loading of the page
var http = createRequestObject();

function createRequestObject()
{
    var request_o;
    var browser = navigator.appName;
    
    if(browser == "Microsoft Internet Explorer")
    {
        /* Create the object using MSIE's method */
        request_o = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        /* Create the object using other browser's method */
        request_o = new XMLHttpRequest();
    }
    return request_o; //return the object
} 



```

The function called when the appropriate button is pressed in html:


```

function getText(el)
{
  http.open('POST','printPHP.php?el='+el, true);
  http.onreadystatechange = handleText;
  http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http.send("printPHP.php?el="+el);
} 



```

And the function to handle the response:


```

function handleText()
{
  if(http.readyState == 4)
  {
      if(http.state == 200)
      {
        var response = http.responseText;
        document.getElementById('textDisplayArea').innerHTML = response;
      }
  }  
} 



```

This might not be a direct answer to your problem, but as i said earlier, perhaps it can help you in some way.

----------


## VerMan

Well, I'm using the same exact code and it does not work with FF 1.5.0.1
so.. nothing left to do  ah yes!  resignation.

----------


## ifunk

Had the same problem myself, and then found this! Firefox won't allow you to use XMLHttpRequest to access a different domain. See the link below.

http://www.captain.at/howto-ajax-per...ttprequest.php

My workaround is to create a passthrough script on my server, so the request acts something like this.

browser -> my server -> remote server -> my server -> browser

A little bit annoying, but hey, that's client-side web development!

----------


## VerMan

and did it work?
could you provide a specific example?

----------


## Thread1

another workaround is to use an invisible IFRAME. although, the target page must call a specific function (handle response) from the main/calling page just to notify that the document is ready. though i am not sure if some of the scripting requirements will work with firefox.  :Stick Out Tongue:

----------


## VerMan

Yes, we could give it a try...
however i'm not even doing the request to a different domain (it is still localhost)

----------


## trends

The  problem is with your Mozillla version.Its older than 1.1.Try using latestversion

----------

