AJAX not working on firefox
Hi...
I'm developing a simple script using AJAX and php to update a database...But the script is running fine on IE but not at all
on Firefox2.0.0.3....Please help me out
Here's my AJAX script
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="http://127.0.0.1/testminor/minor.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
himanjim
Junior Poster in Training
67 posts since Jul 2006
Reputation Points: 14
Solved Threads: 1
Are you getting any specific errors in the firefox error console? I believe FF will reject XMLHTTP connections to pages that aren't on the same domain that the script runs from; I imagine that's amplified by the fact you're trying to connect to 127.0.0.1... Easiest way to get around this is to use relative/server absolute URLS in XMLHTTP opens..
http://developer.mozilla.org/en/docs/AJAX:Getting_Started
As a security feature, you cannot call pages on 3rd-party domains. Be sure to use the exact domain name on all of your pages or you will get a 'permission denied' error when you call open(). A common pitfall is accessing your site by domain.tld, but attempting to call pages with www.domain.tld .
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
Thanks for ur reply...
I tried that + the link you gave me....But still IE accepts it and firefox don't.......
himanjim
Junior Poster in Training
67 posts since Jul 2006
Reputation Points: 14
Solved Threads: 1
Are you getting any specific errors in the firefox error console?
^ it would be helpful to list any errors you may, or may not, be recieving
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64

User info will be listed here.
himanjim
Junior Poster in Training
67 posts since Jul 2006
Reputation Points: 14
Solved Threads: 1
I ftp'd your files up to a live host. There, I arranged the files like so:
www [folder]
|_ temp [folder]
|_ index.html (your html page)
|_ clienthint1.js ( the javascript )
|_ minor.php ( a php file that just echos 'OK', suitable for a test )
I had to change one line of your Javascript:
var url="http://127.0.0.1/testminor/minor.php"
.. changed to ..
var url="minor.php"
This meets the conditions of Firefox not allowing XMLHTTP open to 3rd party hosts; I could equally have used a full URL; but I'd have had to ensure I used the exact same domain to access the page.
The result is here: http://fusiongroups.net/temp
It works for the version of Firefox I have on Windows (1.0.7); try on yours, let me know if it says 'OK' when you click the button... If it does, the XMLHTTP open is working, and this means that there may still be a problem in that the domain you're using to access the page differs from the domain referenced in the XMLHTTP open() URL.
If the page at that link doesn't work (i.e. no OK when clicking the image), I'll swap operating system and have a look on the latest Firefox for you.
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
Thanks a lot for this...
I caught the problem
But as u know php scripts run under server only so as I'm test my scripts on xampp...The address 127.0.0.1 is mandatory for the scripts to run...unless I make directory structure like u have done...
himanjim
Junior Poster in Training
67 posts since Jul 2006
Reputation Points: 14
Solved Threads: 1
Try and test on a 'real server'; or make sure that you always also access the page with the Javascript directly from 127.0.0.1. Providing that you do that; you should be able to omit the 127.0.0.1 from the Javascript code (which also removes the need to change the code when you do go live).
Xampp sets up a system whereby you can access any kind of page in a folder using a http url, so you should certainly be able to make a folder structure similar to the one I did.
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
Ya I'll do that...Thnx a lot
himanjim
Junior Poster in Training
67 posts since Jul 2006
Reputation Points: 14
Solved Threads: 1