Problem with XmlHttpRequest (0x80040111 / nsIXMLHttpRequest.status) on several configurations

G

Greg

Hi,

I've designed a bookmark in Ajax / PHP that I will put soon on
sourceforge.net.
But I've got an very tricky bug.
I try it on some computers with Internet Explorer/Windows, Firefox
1.07/Linux, Firefox 1.5/Linux, Firefox 1.5/Windows and Firefox 1.5/Mac,
Safari/Mac.
It works perfectly on a lot of configurations but, on some PC with
Firefox 1.5/Windows (not all), the Javascript code with XmlHttpRequest
don't work at all and I've got this message when I refresh the webpage
:
--------------------------------------------------------------------------------------
"Erreur : [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://someWebServer/BookmarkAjax/js/requestor.js :: anonymous :: line
52" data: no]
Fichier source : http://someWebServer/BookmarkAjax/js/requestor.js
Ligne : 52"
--------------------------------------------------------------------------------------

Here is the source :
--------------------------------------------------------------------------------------
"function getReadyStateHandler(req, responseXmlHandler) {
// Return an anonymous function that listens to the XMLHttpRequest
instance
return function () {
// If the request's status is "complete"
if (req.readyState == 4) {

// Check that a successful server response was received
// Pass the XML payload of the response to the
// handler function
var debug = document.getElementById("debug");
debug.innerHTML += "<br/>" + req.status + " " + req.statusText;

responseXmlHandler(req.responseXML);

} else { ..."
--------------------------------------------------------------------------------------
This piece of source code comes from an IBM's article :
http://www-128.ibm.com/developerworks/library/j-ajax1/?ca=dgr-lnxw01Ajax

It's very strange because it is working on some configurations and not
at all on others, all based on Firefox 1.5/Windows....
There's a lot of message on the web about this kind of error but I
don't find this exactly case !
I would be glad if somebody could help me.
(I can give you an access on the web application by email if you wan't
to reproduce this bug)
Thanks - Greg
 
V

VK

Greg said:
Hi,

I've designed a bookmark in Ajax / PHP that I will put soon on
sourceforge.net.
But I've got an very tricky bug.
I try it on some computers with Internet Explorer/Windows, Firefox
1.07/Linux, Firefox 1.5/Linux, Firefox 1.5/Windows and Firefox 1.5/Mac,
Safari/Mac.
It works perfectly on a lot of configurations but, on some PC with
Firefox 1.5/Windows (not all), the Javascript code with XmlHttpRequest
don't work at all and I've got this message when I refresh the webpage
:
--------------------------------------------------------------------------------------
"Erreur : [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://someWebServer/BookmarkAjax/js/requestor.js :: anonymous :: line
52" data: no]
Fichier source : http://someWebServer/BookmarkAjax/js/requestor.js
Ligne : 52"
--------------------------------------------------------------------------------------

Here is the source :
--------------------------------------------------------------------------------------
"function getReadyStateHandler(req, responseXmlHandler) {
// Return an anonymous function that listens to the XMLHttpRequest
instance
return function () {
// If the request's status is "complete"
if (req.readyState == 4) {

// Check that a successful server response was received
// Pass the XML payload of the response to the
// handler function
var debug = document.getElementById("debug");
debug.innerHTML += "<br/>" + req.status + " " + req.statusText;

responseXmlHandler(req.responseXML);

} else { ..."
--------------------------------------------------------------------------------------
This piece of source code comes from an IBM's article :
http://www-128.ibm.com/developerworks/library/j-ajax1/?ca=dgr-lnxw01Ajax

It's very strange because it is working on some configurations and not
at all on others, all based on Firefox 1.5/Windows....
There's a lot of message on the web about this kind of error but I
don't find this exactly case !
I would be glad if somebody could help me.
(I can give you an access on the web application by email if you wan't
to reproduce this bug)
Thanks - Greg

Replace:
if (req.status == 200)

to:
if (req.status == 200)||(req.status == 0))

If it helps, ask my why (and you owe me a bottle of Bordeaux of a good
year :-D
 
T

Thomas 'PointedEars' Lahn

VK said:
Replace:
if (req.status == 200)

to:
if (req.status == 200)||(req.status == 0))

`req.status' will never be 0 (and will never be converted to it implicitly,
see ECMAScript Ed. 3, sections 11.9.1 and 11.9.1), there is no such status
code in HTTP and the Microsoft IXMLHttpRequest interface reference, from
which Gecko's XMLHttpRequest derives, does not suggest the property could
hold this value or a value convertible to 0 ever. Therefore, the approach
Ian suggested is, unfortunately unsurprisingly, more reasonable than this.

<URL:http://msdn.microsoft.com/library/en-us/xmlsdk/html/f6de15fc-72e9-418e-b275-d94b0b2045de.asp>
<URL:http://xulplanet.com/references/objref/XMLHttpRequest.html>


PointedEars
 
V

VK

Thomas said:
`req.status' will never be 0 (and will never be converted to it implicitly,
see ECMAScript Ed. 3, sections 11.9.1 and 11.9.1)

I'm wondering what do you have to say about Windows issues if you
stated several times that you are under Linux? Unless you have Windows
installed as well ? Are we cheating? ;-)

FYI: using IXMLHTTPRequest for local (file:\\) files under Windows / IE
6.x returns status 0 is success. So if the said bookmarklet used both
for local and remote files, it may cause a hard to catch erratic
behavior, because for local files status will never be 200 - despite
the file itself will be perfectly loaded.
Also as you cannot set Content-Type for file:\\ (at least for Windows),
XML files loaded from harddrive do no trig XML parser (as it reacts on
Content-Type only, not on file extension), so for your local .xml files
responseXML is always "", only responseText is OK. That is another
erratic behavior which may draw you crazy because the same file may
parse just fine from server and "disappear" as soon as saved as local
file.

ECMAScript Ed. 3 doesn't know about it which is not a suprise of any
kind.

P.S. It is not the fact that it is the OP's problem, but something to
start with. Another explanation can be in Firefox' bookmarlet security
mechanics. We shall move on it if the above suggestion will fail.
 
G

Greg

Thanks for your replies but no one of your suggestions works...

I'm 2 days at my parent's office and they have several PCs with windows
and Firefox 1.5.
It's almost strange because the application works on the server but
doesn't on 2 'office' PCs.

If I print the readyState like this :
-------------------------------------------
try {
document.getElementById("content").innerHTML += req.readyState +
'&nbsp;';
if (req.readyState == 4) {
if (req.status == 200) {
responseXmlHandler(req.responseXML);
} else {
alert("HTTP error: "+req.status);
}
}
} catch(e) {
alert("Exception : " + e);
}
-------------------------------------------
I've got :
- if it's working : 1 1 2 3 3 4
- if not : 1 1

And (on configuration wich it doesn't working), If I refresh the page,
I caught the exception 0x80040111 (NS_ERROR_NOT_AVAILABLE)
[nsIXMLHttpRequest.status]....

I will try to debug this piece of code during the day. If I find a
solution, I'll come back to you.

By the way, this address book project is now on SourceForge :
http://sourceforge.net/projects/gcontact
But, for now, screens are only available in French.
 
V

VK

Greg said:
Thanks for your replies but no one of your suggestions works...

I'm 2 days at my parent's office and they have several PCs with windows
and Firefox 1.5.
It's almost strange because the application works on the server but
doesn't on 2 'office' PCs.

If I print the readyState like this :
-------------------------------------------
try {
document.getElementById("content").innerHTML += req.readyState +
'&nbsp;';
if (req.readyState == 4) {
if (req.status == 200) {
responseXmlHandler(req.responseXML);
} else {
alert("HTTP error: "+req.status);
}
}
} catch(e) {
alert("Exception : " + e);
}
-------------------------------------------
I've got :
- if it's working : 1 1 2 3 3 4
- if not : 1 1

And (on configuration wich it doesn't working), If I refresh the page,
I caught the exception 0x80040111 (NS_ERROR_NOT_AVAILABLE)
[nsIXMLHttpRequest.status]....

The list line sounds really close to
<http://ajaxtoolbox.com/forum/viewtopic.php?p=102&sid=f2be51bc80038174198e5f52e7d91554>

Does it help anyhow if you do not use any req properties in
else-brunch?
 
G

Greg

No... Don't use req properties in else brunch doesn't help...
Thank for the link, I'm looking if it can help me...
 
G

Greg

Wait !
Now, some HttpRequests are working !
But not on all functions on my application...
It's strange but now, I can look for differences between functions wich
are working and thoses which don't !
I think I will soon debug that problem !

Cool.
 
G

Greg

I've found the problem !!!
It's because, when I don't have param to send, I'm sending some request
in this way : "req.send(null);"
And this don't work on some configurations !!!

If I use this : "req.send('');" (with space instead of null)
It's always work !!!!

What a stupid bug !
 
V

VK

Greg said:
I've found the problem !!!
It's because, when I don't have param to send, I'm sending some request
in this way : "req.send(null);"
And this don't work on some configurations !!!

If I use this : "req.send('');" (with space instead of null)
It's always work !!!!

What a stupid bug !

It is not really a bug AFAIK, but a difference between IXMLHTTPRequest
(Microsoft) and XMLHttpRequest (others). At least all MSDN samples seem
to go with "" and all Mozilla samples with null. Never studied it
profoundly though.
 
B

bollax

Can someone tell me why Firefox is not working with AJax and ONLY for
one of my scripts.

the error is
Error: [Exception... "Component returned failure
code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]"
nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://www.stepnstomp.co.uk/java/ajax.js :: alertContents :: line 41"
data: no]
Source File: /java/ajax.js
Line: 41

the code is
Code:
    var http_request = false;
var retvars = "";

function makeRequest(url, parameters, vars) {
http_request = false;
retvars = vars;

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new
ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('AJAX - Giving up :( Cannot create an XMLHTTP
instance');
return false;
}

http_request.onreadystatechange = alertContents;
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length",
parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);

}

function alertContents() {

if (http_request.readyState == 4) {
if (xmlHttp.status == 0 || http_request.status == 200) {
// Call global AJAX function

AJAX(http_request.responseText,retvars);

} else {
alert('There is a problem with AJAX, please contact
support.');
}
}

}

the script is this
Code:
#!/usr/bin/perl

######################
# Set Error Trapping #
######################

use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use warnings;
use strict;
# use diagnostics;

##################
# Use SQL module #
##################
use sql;

# Set File DSN to use
$sql::DSN = "filedsn";

# Read URL & Form data.
my %data = &get_data();

# Get Tune
my @rs = &getSQL("Charts","UserID,Plays","UserID = '$data{'mp3'}'");

# Update Plays
$rs[0]{'Plays'}++;
my $rec = &updSQL("Charts","Plays = $rs[0]{'Plays'}","UserID =
'$data{'mp3'}'");

my $disp = $rs[0]{'Plays'};

# Build Return AJAX data
my $catlist = "Content-type: text/html\n\n
$disp";

# Print AJAX data
print $catlist;
exit();

########

the script runs ok as the DB gets updated, for some reason FF is
erroring when the data is returned. It works fine in IE and the same JS
is used in other places and works in FF, so why is this script playing
up?
 
B

bollax

This may (or may not) help:
<https://bugzilla.mozilla.org/show_bug.cgi?id=238559>
<quote>
Mozilla calls onload() for all HTTP transactions that succeeded. The
only
time it calls onerror() is when a network error happened. Inside the
onerror
handler, accessing the status attribute results in this exception:

Error: [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111
(NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
</quote>

Moral: for Gecko XMLHttpRequest implementation you seem not allowed to
study Ajax object in onerror handler as any attempt to read its
property raise an error.

Thanks for the reply, i'm not a JS expert and alot didn't make sense to
me, but what really doesn't make sense is, the JS I wrote above is a
global file that ALL my AJAX requests use.

So this line : if (http_request.status == 200) where it is erroring is
called all the time, I'm only getting an error for 1 of my scripts.

This to me is indicating that the returned data is different to other
data returned as those requests don't give me this error.

I could understand if FireFox always errored everytime for that line,
but it doesn't, so there has to be something else going on.

It's not because the network/server is unvailable, as the script called
runs and the database gets updated.

I can't see what is different between the scripts that work and the ONE
that doesn't.
 
M

Martin Honnen

http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');

This is not related to your problem but you should only use
overrideMimeType and call it with 'text/xml' as the argument if your
server side application sends XML that you want to parsed into
responseXML but for some reasons can't set the HTTP response
Content-Type header itself to 'text/xml'.

Your server side code however does
# Build Return AJAX data
my $catlist = "Content-type: text/html\n\n
$disp";

so obviously you don't want to send XML but rather HTML (text/html).
Calling http_request.overrideMimeType('text/xml') then is kind of
nonsense and harmful as XMLHttpRequest now expects XML and tries to
parse the response body as XML to build responseXML. That is a wasteful
attempt if you send text/html so consider removing that overrideMimeType
call.
 
V

VK

Thanks for the reply, i'm not a JS expert and alot didn't make sense to
me, but what really doesn't make sense is, the JS I wrote above is a
global file that ALL my AJAX requests use.

So this line : if (http_request.status == 200) where it is erroring is
called all the time, I'm only getting an error for 1 of my scripts.

This to me is indicating that the returned data is different to other
data returned as those requests don't give me this error.

I could understand if FireFox always errored everytime for that line,
but it doesn't, so there has to be something else going on.

It's not because the network/server is unvailable, as the script called
runs and the database gets updated.

I can't see what is different between the scripts that work and the ONE
that doesn't.

Exactly the same script on exactly the same page produces different
results on different machines. Possible explanations:

1. Act of God
Always possible but let's us keep it as the last ressort.

2. Difference in UA.
What is *exactly* the Firefox version on the machine of problem?
What is *exactly* the Firefox version on a machine w/o problem?

3. Difference in OS
What is *exactly* the OS (including installed SP) on the machine of
problem?
What is *exactly* the OS (including installed SP) on a machine w/o
problem?

4. Difference in network connection
Does the machine of problem have *any* difference in network connection
in comparison with other machines.

Also why two different names here (xmlHttp and http_request)?
if (http_request.readyState == 4) {
if (xmlHttp.status == 0 || http_request.status == 200) {
 
B

bollax

thanks for the replies,

To answer a few questions which might help.

1. They are not separate machines, it's the same machine, version of FF
(v1.0.7).
2. http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
thanks for the heads up, the code for making the AJAX request is code
i've used supplied on a forum like this one, so unfortunately it's a
bit of a cargo cult code senario, i know - you don't have to say, but
part of the beauty of the internet is being able to share code so those
not clever enough to write it themselves can still get the benefits,
well that's my excuse!

i can see what your saying though, I removed it and it hasn't helped
though, it's just bizzare how i click the vote for tune link, it calls
the AJAX, sends the request, gets the returned HTML/TEXT and updates
the DOM, cushtie!, but the same thing for the play.cgi gives that
error, I do the same process in both scripts (obviously one updates
votes and the other plays on the DB) but apart from that there is no
difference so why is it crashing in FF for this one script, FF works
fine for the other parts that call the same AJAX script, which is why
i'm scratching my head, completely baffled.
 
B

bollax

OK - I've worked out the problem, don't know how to fix it , if there
is a fix or if it's a major bug in FireFox, but here goes....

I was thinking what does the plays link do that the votes doesn't, the
back end processing and returns are the same, then it dawned on me, aha
the play anchor not only calls the AJAX with the onclick event (as does
vote) but vote's href = "#", but plays is the URL to the MP3 file.

To test my theory I put the href for the votes link to the mp3 file
also and I got the same error in the java console and the DOM didn't
update with the returned TEXT/HTML.

So I conclude that what ever firefox does to get an mp3 file (or maybe
any file) is trashing the AJAX http request, the ajax is running the
request, the file starts to download and that somehow is corrupting the
HTTP ajax request and causing the error.

Can some one try this themselves and confirm the same problem?, does
this make sense to anyone, can it be fixed, is it a bug in FF.

well at least i now know why it is happening, i guess it's a start - lol
 
M

Martin Honnen

I was thinking what does the plays link do that the votes doesn't, the
back end processing and returns are the same, then it dawned on me, aha
the play anchor not only calls the AJAX with the onclick event (as does
vote) but vote's href = "#", but plays is the URL to the MP3 file.

So what exactly do you have,
<a href="someFile.mp3"
onclick="scriptDoingHttpRequest();">link</a>
and someone clicks that link? But then the script would start the
request, the browser would load the href URL in the same window and any
script to process a response is gone as the document with the script is
being replaced.
What exactly do you have, a link with a target attribute?
 
B

bollax

Wow - thanks for the quick reply, there is no target as that would
leave a blank window open. Is the anchor changing the page location so
it's trashing the http request.
<a href="someFile.mp3"
onclick="scriptDoingHttpRequest();">link</a>
and someone clicks that link? But then the script would start the
request, the browser would load the href URL in the same window and any
script to process a response is gone as the document with the script is
being replaced.

that statement is the scenario i have, and it works fine in I.E. , is
it to do with the way FF gets <anchors> to audio files, does firefox
trash the page for ANY anchor but I.E. doesn't?

how can I get round this without loading the mp3 into a new page and
leaving an empty window open?
 
D

dbussert

I have a similat problem I believe. I'm doing something like this in
an iframe
parent.document.getElementById("landmark").src="landmark.php?user=test";
parent.makeRequest();

basically a user makes a change in the iframe, and the iframe calls the
parent window to refresh itself using an ajax call. when I started the
makeRequest() AJAX call before change the SRC I got the ns_error. Now
that I've changed the order, w/ the SRC first and AJAX 2nd the error
went away.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top