jQuery-Parse
jQuery-Parse copied to clipboard
parse.get synchronous
Is it possible have parse.get function as synchronous one ?
Right now, there is no way to override the $.ajax request object through parse.get. However, parse.get does return the $.Deferred object from $.ajax. So I would suggest just using
var req = $.parse.get('Class');
req.done(doSomethig);
req.done(doAnotherThing)
You could make a really easy step system like this..
var step = function(cb){
req.done(cb);
};
Also, take a look at how Jasmine does runs, waitsFor, runs. This is a great way of handling synchronous/async behavior.
What are you trying to build? Would love to give advice if needed. Be well.
Hi There,
I've tried to do just that
var req = $.parse.get('Class'); req.done(doSomethig); req.done(doAnotherThing)
It keeps telling me that done() is undefined. So I thought maybe my jQ library was old but even complete() doesn't work.
Any ideas?
@abusu-noggin I'm sorry, I was mistaken. The $.parse.get does not return a $.Deferred object. It just returns $.parse. Instead you need to pase $.parse.get('Class', callback, error)
However, here's a nice wrapper for a getting a promise for a get request.
$.parse.getPromise = function(class){
var dfd;
$.parse.get(class, function(data){
dfd.resolve(data);
}, function(data){
dfd.reject(data);
});
return dfd;
}