NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
xmlHttp requests - Firefox and IE


Joined: 24 Mar 2010
Posts: 19
Location: Wheeling, IL
Reply with quote
Having a problem with FireFox. A very simple ajax request that returns a text string fails in firefox 3.6.7 but runs perfectly in IE8.
( I am not sure about earlier firefox versions)

The target script is on a server within the current domain. I print the status values as the process flows and in firefox I see:

Request status: 1 (loading)
Request status: 2 (loaded)
Request status: 4 (done)

and no result string.


but in 'IE8' I get

Request status: 1 (loading)
Request status: 2 (loaded)
Request status: 3 (interactive)
Request status: 4 (done)

plus the result string.

Am I forgetting something for firefox? Why am I not getting status 3 in firefox?

Thanks,
Bill
View user's profileFind all posts by bwls@earthlink.netSend private messageSend e-mail


Joined: 11 Apr 2010
Posts: 90
Location: Prague, Czech Republic
Reply with quote
Hello. This is native behavior of the browsers. Since IE and Mozilla have different implementations of xmlHttpRequest, they are behaving differently. The status event you can count on is the Request status: 4 (done). Most browsers also implement status 1 and many implement status 2. Status 3 is tricky, it means, that document has been loaded partially and is available as such - i.e. only partial content is available at the moment. It might happen with larger request data or slower connection, but in general, the request data are obtained in one package, so browsers simply skip event 3.
View user's profileFind all posts by fibizaSend private message


Joined: 24 Mar 2010
Posts: 19
Location: Wheeling, IL
Reply with quote
Thanks for the response.

ON the firefox error console I get:


Warning: Warning: Ignoring unrecognized chrome manifest instruction.
Source File: file:///C:/Documents%20and%20Settings/bwls/Application%20Data/Mozilla/Firefox/Profiles/lt6ftwwu.default/extensions/%7Bd10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d%7D/chrome.manifest
Line: 57

Chrome was installed on this PC and it was a beast to get removed. Could it be that remnants of Chrome are interfering? Would a uninstall / reinstall of firefox correct this situation?

I am at a loss here so any help would be appreciated.
View user's profileFind all posts by bwls@earthlink.netSend private messageSend e-mail


Joined: 11 Apr 2010
Posts: 90
Location: Prague, Czech Republic
Reply with quote
The "chrome" in this context means something else. Just google "The_Chrome_URL" for explanation in MDC - should be the first googled link.

There might be two possible reasons for the behavior you described. Either your FireFox installation is corrupt, or the problem is that some JavaScripts do work in IE, but they don't work in other browsers like FireFox and vice versa.

If the former is the case, try reinstalling FireFox or alternatively go to Tools / Add-ons and review FireFox plug-ins. Ttry disabling them one by one to try to find the problem.

If the latter is the case, then you should try another script for xmlHttpRequest, which would hopefully work ok. For example try JQuery (just google it) and their Ajax API.
View user's profileFind all posts by fibizaSend private message


Joined: 24 Mar 2010
Posts: 19
Location: Wheeling, IL
Reply with quote
I am working through "jQuery In Action" right now and will try as soon as I get to the ajax section.

FYI: FF does get to ready state 4 but throws an error on the xmlhttp.send(null) command everytime I am going to a non-local script. The remote url is "http://server4/phptest.php". it works fine when I use the local url of "phptest.php". IE works fine on both url's.

I will try to capture the specific js error and get back to you.

Thanks.
View user's profileFind all posts by bwls@earthlink.netSend private messageSend e-mail


Joined: 11 Apr 2010
Posts: 90
Location: Prague, Czech Republic
Reply with quote
What are you describing might be related to AJAX's "sandbox" model. This means, that for security reasons you cannot do cross-domain requests, at least it should not be allowed by the browser according to specs. IE probably has buggy implementation, so it allows it, but Mozilla throws error, which is exacly by the specs. Could this be it? If you need to do cross-domain xmlHttp requests, there are some workarounds, e.g. you can make local PHP script, which would return remote JS content.
View user's profileFind all posts by fibizaSend private message
Cross -Domain http


Joined: 24 Mar 2010
Posts: 19
Location: Wheeling, IL
Reply with quote
This sounds like a real possibility. You mentioned a work-around. Can you point me to an explanation or an example? For the project I am working on I need to access two different remote servers to obtain results.

But in the test case, both the workstation and the server are in the same domain. (20 ft apart). And the ip,s differ only by the last octet. Domain masks are 255.255.255.0 in both cases.

One other tidbit, I have apache running on both the local PC and on the remote server. Maybe this is why it is triggering the X-Domain block.

Thanks.
View user's profileFind all posts by bwls@earthlink.netSend private messageSend e-mail


Joined: 24 Mar 2010
Posts: 19
Location: Wheeling, IL
Reply with quote
Here is the console for the ajax process:

GET http://server4/phptest.php 200 OK 68ms phptest.js (line 44)


Response Headersview source
Date Mon, 26 Jul 2010 12:09:08 GMT
Server Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By PHP/5.3.1
Content-Length 183
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/xml

Request Headersview source
Host server4
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.Cool Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Referer http://localhost/ajax/php2-test/phptest.html
Origin http://localhost

To me it looks as though I am getting a 200 response and a returned packet of 183 bytes which seems right ( a small xml doc). The remote script:

<?php
header('Content-Type: text/xml');
$dom = new DOMDocument();
$response = $dom->createElement('response');
$dom->appendChild($response);
$books = $dom->createElement('books');
$response->appendChild($books);
$title = $dom->createElement('title');
$titleText = $dom->createTextNode('AJAX and PHP: Building Modern Web Applications, 2nd Ed');
$title->appendChild($titleText);
$isbn = $dom->createElement('isbn');
$isbnText = $dom->createTextNode('978-1904817726');
$isbn->appendChild($isbnText);
$book = $dom->createElement('book');
$book->appendChild($title);
$book->appendChild($isbn);
$books->appendChild($book);
$xmlString = $dom->saveXML();
echo $xmlString;
?>
If I execute the script in IE8 it displays a header: <?xml version="1.0" ?> but in FF it doesn't. Why would FF omit the header?

Thanks but still perplexed. I am looking into jQuery and will try it there as soon as I can figure it out and get it to work.
View user's profileFind all posts by bwls@earthlink.netSend private messageSend e-mail


Joined: 11 Apr 2010
Posts: 90
Location: Prague, Czech Republic
Reply with quote
The strange thing is, that when I test your example, I get valid response from both FF (3.6.Cool and IE 8. I have my own AJAX framework, but in any case, it seems, that the response is returned ok. According to my logs, the request on both browsers also goes through all of the states 2 (loaded), 3 (interactive) and 4 (completed) and ends up with 200 OK header. Could the problem be in your server PHP configuration only? I use Zend Server CE (latest). If you have enabled "magic_quotes_gpc" in your PHP, it might break the response also. A would also try adding "charset" parameter for your header, so the full header for your XML document should look like this:
Code:
header('Content-type: text/xml; charset=utf-8');
View user's profileFind all posts by fibizaSend private message
xmlHttp requests - Firefox and IE
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic