Problem with handling exception when sending data by ajax with jQuery

0

i got following part of one of functions

        if(continiueSend)
        {
            $.ajax
            ({
                type: "POST",
                url: "mailer.php",
                data: "somestestdata",
                timeout: 5000,
                success: function(a) 
                {
                    alert(a);
                },
                error: function (xhr, ajaxOptions, thrownError)
                {
                    alert(xhr.status);
                    alert(thrownError);
                }    
            });
        }

And it works great when server is ok, requested data are sent in less than 100ms, in case when i turnoff sever it also works great,script reports errors as it expected, but there is problem when server is busy

When time of sending data exceeds limit set with "timeout:" error handling as specified in "error:" isn't fired, and in console appears following information

uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://127.0.0.1/site/index.php?article=2 :: anonymous :: line 252" data: no]

Line 252 is first line of mentioned code. I tryied to put code inside IF brackets into try...catch but with no results.

How I can properly detect this exception to handle it the way i want?

MTH

jquery
ajax
exception
exception-handling
timeout
asked on Stack Overflow Oct 4, 2009 by MoreThanChaos

1 Answer

1

Are you sure the error callback isn't actually called? Place a try-catch block inside the error function. Remember, this is called asynchronously. A try-catch block outside of it won't do anything. Probably the exception is caused when you try to read the error.

answered on Stack Overflow Oct 4, 2009 by kgiannakakis

User contributions licensed under CC BY-SA 3.0