-
January 1st, 2006, 03:08 PM
#1
AJAX does not work with FireFox
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
-
January 1st, 2006, 03:12 PM
#2
Re: AJAX does not work with FireFox
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.
-
January 1st, 2006, 03:14 PM
#3
Re: AJAX does not work with FireFox
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
-
January 1st, 2006, 03:29 PM
#4
Re: AJAX does not work with FireFox
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?
-
January 24th, 2006, 03:51 AM
#5
Re: AJAX does not work with FireFox
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>
-
February 20th, 2006, 04:15 AM
#6
Re: AJAX does not work with FireFox
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
-
March 13th, 2006, 05:09 AM
#7
Re: AJAX does not work with FireFox
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!
PHP Code:
//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:
PHP Code:
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:
PHP Code:
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.
-
March 28th, 2006, 04:40 PM
#8
Re: AJAX does not work with FireFox
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.
-
March 28th, 2006, 06:56 PM
#9
Re: AJAX does not work with FireFox
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!
-
April 20th, 2006, 12:53 PM
#10
Re: AJAX does not work with FireFox
and did it work?
could you provide a specific example?
-
April 22nd, 2006, 12:32 AM
#11
Re: AJAX does not work with FireFox
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.
Busy
-
April 25th, 2006, 08:06 PM
#12
Re: AJAX does not work with FireFox
Yes, we could give it a try...
however i'm not even doing the request to a different domain (it is still localhost)
-
May 5th, 2006, 06:43 AM
#13
Re: AJAX does not work with FireFox
The problem is with your Mozillla version.Its older than 1.1.Try using latestversion
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|