Side navigation
#10552 closed bug (invalid)
Opened October 21, 2011 01:06PM UTC
Closed November 05, 2011 08:15AM UTC
Last modified March 10, 2012 05:10AM UTC
Ajax response status 0
Reported by: | jonatan.wallgren@openbet.com | Owned by: | jonatan.wallgren@openbet.com |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Using jQuery.load can fail under some use cases even if the returned data is correct.
Consider following use case:
A webapp is served from a web server using ajax requests to fetch additional web pages using jquery load. All is fine.
Said webapp gets packaged with phonegap, now the resources will be fetched from the local file system on the device. On IOS, and possibly on other devices as well, the returned status code from the jQuery.load request will be zero even though the data in jqXHR.responseText will be returned correctly.
This documentation from Mozilla
https://developer.mozilla.org/En/Using_XMLHttpRequest#Example.3a.c2.a0Non-HTTP_synchronous_request
states that XMLHttpRequest states "Despite its name, XMLHttpRequest can be used for non-HTTP requests." which I would guess a read from the local file system would be.
Also from the same document:
"The key thing to note here is that the result status is being compared to 0 for success instead of 200. This is because the file and ftp schemes do not use HTTP result codes."
Currently how you guys determine if the response is an error seems to be in this line of code:
https://github.com/jquery/jquery/blob/master/src/ajax.js#L520
"if ( status >= 200 && status < 300 || status === 304 )"
Adding a passing condition for zero like this:
"if ( status >= 200 && status < 300 || status === 304 || status === 0)"
solves my immediate problem, I get my ajax request data back correctly. What do you guys think of adding this passing condition to the jQuery source? If this solution seems to be to fragile it could maybe be an idea introduce some ways of suppressing error code 0?
Attachments (0)
Change History (2)
Changed October 22, 2011 01:35AM UTC by comment:1
owner: | → jonatan.wallgren@openbet.com |
---|---|
status: | new → pending |
Changed November 05, 2011 08:15AM UTC by comment:2
resolution: | → invalid |
---|---|
status: | pending → closed |
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
Do you have a test case? What is the protocol you are using? Did you try setting
isLocal
? http://api.jquery.com/jQuery.ajax/