Exception with xmlHttp.status in mozilla/firefox

P

Prasad

Hi all,

I wanted to know whether my page is connecting to server or not using
xmlHttp request.
For that , I am using one condition in onreadystatechange function as..
function xxx()
{
if(xmlhttp.readyState==4)
{

if(xmlhttp.status!=200)
{
error_handler();
}

----------
---------------------
}

}


This is working fine in IE when there is no connectivity with server( I
stoped the server)..

But it's giving exception in mozilla/firefox when I stopped the server
(only when I stop .),

at line 65 in my code, as


[Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost/teamkollab/chat2/chat-ajax.js :: responseDisplayChat
:: line 65" data: no]


line 65 is
-------------- if(xmlhttp.status != 200)

I could not access the xmlhttp.status variable .

Does it mean that xmlhttp object won't be returned with status code
when it can not connect to a page ??
If yes, what will it return to know the status ??


How could I solve this to not to get such exception ?

Please help me out ,
Thanks in advance
 
P

Peter Michaux

Prasad said:
But it's giving exception in mozilla/firefox when I stopped the server
(only when I stop .),

at line 65 in my code, as


[Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost/teamkollab/chat2/chat-ajax.js :: responseDisplayChat
:: line 65" data: no]


line 65 is
-------------- if(xmlhttp.status != 200)

I could not access the xmlhttp.status variable .

Does it mean that xmlhttp object won't be returned with status code
when it can not connect to a page ??
If yes, what will it return to know the status ??


How could I solve this to not to get such exception ?

The Yahoo! UI connection manager
(http://developer.yahoo.com/yui/connection/) puts the xmlhttp.status
line in a try-catch block because of Firefox

try
{
if(o.conn.status !== undefined && o.conn.status != 0){
httpStatus = o.conn.status;
}
else{
httpStatus = 13030;
}
}
catch(e){
// 13030 is the custom code to indicate the condition -- in
Mozilla/FF --
// when the o object's status and statusText properties are
// unavailable, and a query attempt throws an exception.
httpStatus = 13030;
}

I haven't had a chance to study this more and their documentation
unfortunately doesn't specify what conditions calse the unavailability.

Flanagan's fifth edition simply states that reading the status when
readystate is less than 3 causes an error. Since XHR is not
standardized I imagine it was one of his observations in a particular
browser.

Peter
 
P

Prasad

Peter said:
Prasad said:
But it's giving exception in mozilla/firefox when I stopped the server
(only when I stop .),

at line 65 in my code, as


[Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost/teamkollab/chat2/chat-ajax.js :: responseDisplayChat
:: line 65" data: no]


line 65 is
-------------- if(xmlhttp.status != 200)

I could not access the xmlhttp.status variable .

Does it mean that xmlhttp object won't be returned with status code
when it can not connect to a page ??
If yes, what will it return to know the status ??


How could I solve this to not to get such exception ?

The Yahoo! UI connection manager
(http://developer.yahoo.com/yui/connection/) puts the xmlhttp.status
line in a try-catch block because of Firefox

try
{
if(o.conn.status !== undefined && o.conn.status != 0){
httpStatus = o.conn.status;
}
else{
httpStatus = 13030;
}
}
catch(e){
// 13030 is the custom code to indicate the condition -- in
Mozilla/FF --
// when the o object's status and statusText properties are
// unavailable, and a query attempt throws an exception.
httpStatus = 13030;
}

I haven't had a chance to study this more and their documentation
unfortunately doesn't specify what conditions calse the unavailability.
Thanks,some how , I got rid of the problem ,but am still wondering why
it's giving exception when we are reading status variable ("only when
browser can't get any response from server ") . Doesn't it mean that
it's bug with firefox ??

Anyways , Thanks a lot ..
 
P

Prasad

Peter said:
Prasad said:
But it's giving exception in mozilla/firefox when I stopped the server
(only when I stop .),

at line 65 in my code, as


[Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost/teamkollab/chat2/chat-ajax.js :: responseDisplayChat
:: line 65" data: no]


line 65 is
-------------- if(xmlhttp.status != 200)

I could not access the xmlhttp.status variable .

Does it mean that xmlhttp object won't be returned with status code
when it can not connect to a page ??
If yes, what will it return to know the status ??


How could I solve this to not to get such exception ?

The Yahoo! UI connection manager
(http://developer.yahoo.com/yui/connection/) puts the xmlhttp.status
line in a try-catch block because of Firefox

try
{
if(o.conn.status !== undefined && o.conn.status != 0){
httpStatus = o.conn.status;
}
else{
httpStatus = 13030;
}
}
catch(e){
// 13030 is the custom code to indicate the condition -- in
Mozilla/FF --
// when the o object's status and statusText properties are
// unavailable, and a query attempt throws an exception.
httpStatus = 13030;
}

I haven't had a chance to study this more and their documentation
unfortunately doesn't specify what conditions calse the unavailability.

Flanagan's fifth edition simply states that reading the status when
readystate is less than 3 causes an error. Since XHR is not
standardized I imagine it was one of his observations in a particular
browser.

Peter
 
V

VK

Prasad said:
Thanks,some how , I got rid of the problem ,but am still wondering why
it's giving exception when we are reading status variable ("only when
browser can't get any response from server ") . Doesn't it mean that
it's bug with firefox ??

Difficult to say. I mean it's already filed, but still seems discussed
either call it a "bug" or hell on it and so promote it into "feature"
:)

See <https://bugzilla.mozilla.org/show_bug.cgi?id=238559>, Comment #2
explains your particular case.
 
V

VK

VK said:
See <https://bugzilla.mozilla.org/show_bug.cgi?id=238559>, Comment #2
explains your particular case.

Respectively on async calls you should always check .status inside
try{} block. On a network error IE will report the relevant status code
by MS tables (linked in the bug thread) while Gecko will simply raise
an exception you have to catch and interprete then as "Some network
error happened". In this aspect I see the YI script as error prone.
 

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

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top