Has anyone ever successfully tracked down uncaught exception during ajax request?

1

How do ajax know whether it failed or succeeded if server side doesn't echo anything back?

$.ajax(error:..,success:..)

I met with this exception in my test:

uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.statusText]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://localhost/script/tab.js :: anonymous :: line 69" data: no]

The server side code is :

$id = process();

And for the purpose of testing,I have exit() in process();

Is that the reason for this exception?If so,why?

EDIT I looked over to the line that cause exception,it's the error handling function of $.ajax()

error:function(XMLHttpRequest, textStatus, errorThrown){ 
    alert(XMLHttpRequest.statusText);alert(textStatus);alert(errorThrown);
}

Anything wrong here?

php
jquery
ajax
xmlhttprequest
asked on Stack Overflow Sep 21, 2009 by omg • edited Sep 21, 2009 by omg

7 Answers

1

The httprequest also returns a status such as 200 == ok, 404 == not found, 12152 == connection closed by server and so on.. Just read up on the status id's what they mean so you can look for them. you can also for debugging reasons just write out myhttprequest.status to the document and it shows what status it returned.

answered on Stack Overflow Sep 21, 2009 by Jonas B • edited Sep 21, 2009 by Jonas B
0

This depends on the status code the request returns. A successful request returns a status code in the range of 2xx, an error is in the range of 4xx of 5xx.

For more information see Wikipedia: List of HTTP status codes.

answered on Stack Overflow Sep 21, 2009 by Edwin V.
0

It would still get a response from the server, with the data part of it being empty. If it got no response at all, that would be an error.

answered on Stack Overflow Sep 21, 2009 by Rik Heywood
0

http://docs.jquery.com/Ajax/jQuery.ajax#options

Give an option for success and error These functions will be called after the call is made.

answered on Stack Overflow Sep 21, 2009 by Natrium
0

There are four possible scenarios that you could get:

  • the server isn't there or refuses the connection (this is identifiable by the sockets library that the browser uses, which will report the connection failure)
  • the connection works and the server returns a non-success error code - this comes back in the header. Indeed, the request can succeed (200 code) even with an empty body, that's perfectly valid
  • the connection comes up but the server fails to respond - I'm not clear on the details of this, but i'd expect the JS to eventually time out because no response was received and return a failure based on that.
  • the connection comes up but the server responds incorrectly (e.g. no headers) - the JS implementation should return this as an error.

In any case, all the error scenarios are handled by the Javascript core's XMLHttpRequest implementation - jQuery just wraps it up with slightly tidier interface.

In your case (now you've provided more information) I would recommend that you use Firebug to see what the server response to your request is. That said, you shouldn't be getting an exception for anything inappropriate from the server, the JS should call the same error callback for all the above cases.

answered on Stack Overflow Sep 21, 2009 by ijw • edited Sep 21, 2009 by ijw
0

are you missing { } ?

$.ajax(error:..,success:..)

should be

$.ajax( { error: function( ){ } } );

if that's it, sorry dude, that would be annoying to have spent that much time on, haha

answered on Stack Overflow Dec 17, 2009 by Dan Beam
0

I fixed this by specifying a timeout in my ajax call. The ajax timeout was just giving up after X amount of time. Even though the page ended up returning data, the ajax object just gave up and bailed, but threw this error.

answered on Stack Overflow Feb 11, 2011 by dubRun

User contributions licensed under CC BY-SA 3.0