Skip to main content

Bug Tracker

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 jitter comment:1

cc: → jaubourg
component: unfiledajax
owner: → invisible_stefan
priority: undecidedhigh
status: newpending

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

Changed February 09, 2011 01:22PM UTC by anonymous 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 jaubourg comment:3

jQuery doesn't "get confused" at all:

http://jsfiddle.net/J2WxM/1/

Are you sure the code in your success handler doesn't throw an exception?

Changed February 09, 2011 05:14PM UTC by jaubourg comment:4

resolution: → worksforme
status: pendingclosed

Changed May 06, 2011 10:33PM UTC by vasken@gigaom.com comment:5

The provided example does work correctly, but consider the following:

http://jsfiddle.net/dmS2A/

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 vasken@gigaom.com 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 jaubourg 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.