I am having trouble learning to use the new jQuery Deferred.
The does an ajax call and i want to return the data of the ajax call.
checkIDExists = function(id){
var exists = false;
$.ajax({
data: {
method: "idExists",
id: id
},
success: function(data){
if(data == 'true'){
exists = true;
}
}
}).done(function(){
return exists;
}).fail(function(){
return false;
});
};
I know the problem comes in when i try to return something inside of the done() or fail() functions which doesn’t return it for the checkIdExists() function. How do i work around this?
Ajax itself works asynchronously, so function checkIDExists completes earlier then ajax call returns data from the server.
In your case I wouldn’t rely on return value of checkIDExists function, but I would overwrite the function using CPS approach.