about jQuery timeout error process

1

Recently, I found some error about timeout.

Please see below code.

  • jQuery timeout : 5000 ms
  • Servlet sleep : 10000 ms

Client side Javascript

    $.ajaxSetup({
    url: "http://localhost:8888/{mydomain}",
    timeout : 5000,
    error:function (xhr, textStatus, thrownError){
        switch(xhr.status) {
            case 0 :
                $('#msg').append("0");
                break;
            case 404:
                $('#msg').append("404 ERROR."); 
                break;
            case 500:
                $('#msg').append("500 ERROR.");
                break;
            case 408:
                $('#msg').append("408 ERROR.");
                break;              
            default :
                $('#msg').append(xhr.status);
                break;
        }
    }       
});

$(function() {
        $.ajax({
            type: "GET",
            dataType:"JSON",
            data:{send a some data},
            success:function(response){
                alert(response);
            }
        })      
});

Java process

@Path("/{mydomain}")
public class DummyResource {

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String getMethod() throws Exception {

        try {
            Thread.sleep(10000);            
        } catch(InterruptedException ie) {
            throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
        }
        return "hello!";
    }
}

But, error is different between Safari and Firefox.

  1. Safari (timeout error: I think, this result is right.)

    > GET //localhost:8888/{mydomain} Aborted
    
  2. Firefox(success, but some error occured)

    > GET //localhost:8888/{mydomain} 200 OK 10.01s
    uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: //localhost:8888/{mydomain}/ajax.html :: anonymous :: line 20" data: no]
    

My System Info

MacOSX : 10.6.5
Browser: Safari 5.0.3, Firefox 3.6.8

javascript
jquery
ajax
timeout
xmlhttprequest
asked on Stack Overflow Dec 17, 2010 by morinooji • edited Dec 17, 2010 by Yi Jiang

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0