سؤال

I would like access to the original jqXHR object as called by $.ajax(ajaxOpts), is this possible somehow? All I get now is a promise.

                var jqXHR = $.ajax(ajaxOpts)
                    .done(dfd.resolve)
                    .fail(dfd.reject)
                    .then(next, next);
هل كانت مفيدة؟

المحلول

From the docs:

The jqXHR objects returned by $.ajax() as of jQuery 1.5 implement the Promise interface, giving them all the properties, methods, and behavior of a Promise (see Deferred object for more information)

You already get a jqXHR object (which is a superset of the XMLHTTPRequest object). It just implements the promise interface.

var jqXHR = $.ajax(ajaxOpts);
console.log(typeof jqXHR.abort);
jqXHR.done(dfd.resolve)
    .fail(dfd.reject)
    .then(next, next);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top