Reputation: 1025
I am trying to poll a database for the values of a few columns the polling function works. However I would like to be able to use a deferred to let the function that calls the polling function to know when it is complete. Using what I have below I am getting either a has no method 'resolve' or a has no method 'promise' error
//how I call the poll function
poll(Guids.Creation,$.Deferred);
var poll = function (guid,defer) {
var timeOut = 3000,
url = 'handler.ashx',
data = {
cmd : 4 ,guid : guid
};
App.Generic.ajax(url,"GET", this, data).done(function (data) {
var orderStatusJSON = $.parseJSON(data);
if (orderStatusJSON.hasOwnProperty('dateFinished') && orderStatusJSON.dateFinished === '') {
setTimeout(function(){poll(guid,defer)}, 3000);
} else {
if (orderStatusJSON.hasOwnProperty('output')) {
var successRegEx = /\bsuccess\b/i,
errorRegEx = /\berror\\b/i;
if(successRegEx.test(orderStatusJSON.output)) {
defer.resolve(orderStatusJSON);
} else if (errorRegEx.test(orderStatusJSON.output)) {
defer.resolve(orderStatusJSON);
} else {
defer.resolve(orderStatusJSON); //execute statement
}
}
}
});
return defer.promise();
};
Upvotes: 0
Views: 505
Reputation: 14053
$.Deferred
is just a method of the jQuery object. You need to construct a Deferred object to use it:
var deferred = new $.Deferred();
Upvotes: 2