Side navigation
#8211 closed bug (worksforme)
Opened February 08, 2011 04:28PM UTC
Closed February 09, 2011 05:14PM UTC
Last modified May 07, 2011 02:13AM UTC
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; } });
Attachments (0)
Change History (7)
Changed February 08, 2011 06:42PM UTC by comment:1
cc: | → jaubourg |
---|---|
component: | unfiled → ajax |
owner: | → invisible_stefan |
priority: | undecided → high |
status: | new → pending |
Changed February 09, 2011 01:22PM UTC by comment:2
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
Changed February 09, 2011 03:11PM UTC by comment:3
jQuery doesn't "get confused" at all:
Are you sure the code in your success handler doesn't throw an exception?
Changed February 09, 2011 05:14PM UTC by comment:4
resolution: | → worksforme |
---|---|
status: | pending → closed |
Changed May 06, 2011 10:33PM UTC by comment:5
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
Changed May 06, 2011 10:36PM UTC by comment:6
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',
Changed May 07, 2011 02:13AM UTC by comment:7
Replying to [comment:6 vasken@…]:
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