Skip to main content

Bug Tracker

Side navigation

#13923 closed bug (wontfix)

Opened May 22, 2013 08:27PM UTC

Closed May 23, 2013 12:33AM UTC

Last modified January 30, 2014 11:28PM UTC

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/

Attachments (0)
Change History (3)

Changed May 22, 2013 11:30PM UTC by jaubourg comment:1

component: unfiledajax
owner: → jaubourg
priority: undecidedblocker
status: newassigned

Confirmed in both 1.x and 2.x.

Changed May 23, 2013 12:33AM UTC by jaubourg comment:2

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
        }
    } );
} );

Changed January 30, 2014 11:28PM UTC by anonymous comment:3

} 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