-1

The jqXHR object used by jQuery.ajax has a property statusText, which can have two values when aborting the XHR: canceled and abort. When is the former used and when is the latter?

niutech
  • 28,923
  • 15
  • 96
  • 106

1 Answers1

0

Here is the relevant source code of ajax.js:

        // Default abort message
        strAbort = "canceled",

        // Fake xhr
        jqXHR = {

            ...

            // Cancel the request
            abort: function( statusText ) {
                var finalText = statusText || strAbort;
                if ( transport ) {
                    transport.abort( finalText );
                }
                done( 0, finalText );
                return this;
            }
        };

        ...

        // Apply prefilters
        inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );

        // If request was aborted inside a prefilter, stop there
        if ( state === 2 ) {
            return jqXHR;
        }

        ...

        // aborting is no longer a cancellation
        strAbort = "abort";

It reads that if you abort the XHR request in the prefilter, then the statusText is canceled, otherwise it is abort.

niutech
  • 28,923
  • 15
  • 96
  • 106
  • hmm... Does that include the beforeSend callback? I would expect it to be "canceled" if it was aborted before any request was actually sent. – Kevin B Apr 20 '17 at 15:40
  • @KevinB No, the `canceled` status is returned when you use [jQuery.ajaxPrefilter](https://api.jquery.com/jquery.ajaxprefilter/), `abort` is returned when you use `beforeSend`. – niutech Apr 20 '17 at 15:52