#8211 closed bug (worksforme)
statusCode is incorrectly handled
Reported by: | invisible_stefan | Owned by: | invisible_stefan |
---|---|---|---|
Priority: | high | Milestone: | 1.next |
Component: | ajax | Version: | 1.5 |
Keywords: | Cc: | jaubourg | |
Blocked by: | Blocking: |
Description
Hi all,
I would like to react on http status-codes (like 200, 201 or 202) with the new feature (http://api.jquery.com/jQuery.ajax). But the function is ignoring my 201 and 202 callbacks.
This error occures with firefox-4.0_b10 and chromium-9.0
I'm looking forward to fix this little issue.
Regards Stefan
My code-snipped:
jQuery.ajax({ url: url, dataType: 'json', statusCode: { 404:function() { alert("404"); }, 200:function() { alert("200"); }, 201:function() { alert("201"); }, 202:function() { alert("202"); } }, success: function(data){ switch(data.status) { case 'done': /* display it to the User */ break; } });
Change History (7)
comment:1 Changed 12 years ago by
Cc: | jaubourg added |
---|---|
Component: | unfiled → ajax |
Owner: | set to invisible_stefan |
Priority: | undecided → high |
Status: | new → pending |
comment:2 Changed 12 years ago by
Hi all
I found a solution for the problem:
jQuery.ajax({ url: url, dataType: 'json', statusCode: { 404:function() { alert("404"); }, 200:function() { alert("200"); }, 201:function() { alert("201"); }, 202:function() { alert("202"); } }, });
Somehow jQuery get's confused if the success/error feature is used along with the statusCode-Map.
Regards Stefan
comment:3 Changed 12 years ago by
jQuery doesn't "get confused" at all:
Are you sure the code in your success handler doesn't throw an exception?
comment:4 Changed 12 years ago by
Resolution: | → worksforme |
---|---|
Status: | pending → closed |
comment:5 follow-up: 6 Changed 12 years ago by
The provided example does work correctly, but consider the following:
This returns the appropriate 200 alert, but changing the url to a 404 page does not return the expected 404:
url: 'http://www.404errorpages.com/', }}}a
comment:6 follow-up: 7 Changed 12 years ago by
Sorry, the example for the second situation should read like this (essentially hitting against a 404 page instead of an existing page):
url: 'http://www.404errorpages.com/asdfasdfa.html',
comment:7 Changed 12 years ago by
Replying to [email protected]…:
Sorry, the example for the second situation should read like this (essentially hitting against a 404 page instead of an existing page):
url: 'http://www.404errorpages.com/asdfasdfa.html',
This example uses dataType jsonp and, as is stated on the documentation (see the error option description here: http://api.jquery.com/jQuery.ajax/), cross-domain jsonp requests won't notify errors... so no 404.
http://jsfiddle.net/54uXZ/ works perfectly.
Thanks for taking the time to contribute to the jQuery project by writing a bug report.
Can you maybe submit a link to a reduced test case (some website which sends the appropriate headers), that reproduces the issue you are experiencing. So that we can investigate this issue further. Also make sure to read the link given below, in order to provide a most useful bug report.
How to report bugs