Skip to content Skip to sidebar Skip to footer

How To Check If Object Is An JQuery Xhr Object

Basically, I am in a situation where I would like to check if an object is a jQuery XHR (jqXHR -- such as is returned by .ajax() requests) -- not just a regular Deferred object. I

Solution 1:

You could check for any property that a deferred should have, such as done, fail, always, state, etc.

done seems like something a deferred should have (which promises also have), that isn't very common among other jQuery objects.

var def = new $.Deferred();

if ('done' in def)

and to check if it's a promise

var ajax = $.ajax({
    url : 'something'
})

isPromise = 'abort' in ajax;

Post a Comment for "How To Check If Object Is An JQuery Xhr Object"