Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13923 closed bug (wontfix)

statusCode can not be initialized as an ajax option in $.ajaxPrefilter

Reported by: thomasrosshallock Owned by: jaubourg
Priority: blocker Milestone: None
Component: ajax Version: 2.0.0
Keywords: Cc:
Blocked by: Blocking:

Description

Here is a demonstration of this issue: http://jsfiddle.net/antialias/BbQHr/

Change History (3)

comment:1 Changed 7 years ago by jaubourg

Component: unfiledajax
Owner: set to jaubourg
Priority: undecidedblocker
Status: newassigned

Confirmed in both 1.x and 2.x.

comment:2 Changed 7 years ago by jaubourg

Resolution: wontfix
Status: assignedclosed

OK, I've looked into this and it's quite tricky to fix because we have some nasty interaction with jqXHR.statusCode() so what I'd recommend is to actually use jqXHR.statusCode() instead of manipulating the option directly:

$.ajaxPrefilter( function( _, jqXHR ) {
    jqXHR.statusCode( {
        404: function() {
            // Your code here
        }
    } );
} );

comment:3 Changed 7 years ago by anonymous

} else if ( type === "error" ) {
  complete(
    // file protocol always yields status 0, assume 404
    xhr.status || 404,
    xhr.statusText
  );

And this is what you get

http://screencast.com/t/3tQyS7Dakb5y

Note: See TracTickets for help on using tickets.