callback - Jquery deferred call back oddness -
I was playing with call back and deferred work in jQuery and wondering if someone could tell me why this Works
get_each_total = function (callback) {var request; Request = []; Var url; Url = "http://otter.topsy.com/search.js?callback=?&ipikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d"; Return request. Push ($ .getJSON (URL, function (data) {})); Refund $. Then ($ (requests). Then (function () {callback ();}, function () (return warning ("There was an error in communicating with a remote library, try again in some");}); }; Get_each_total_broken = function (callback) {var request: request = []; Var url; url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q= Justin + bieber & window = d "; return request.push ($ .getJSON (url, function (data) {})) return $ then again ($ (requests). Then (function () {callback ();} , Function () (return warning ("a remote library Scope There was an error in communication with, try again in ");});}; $ (function () {Get_each_total (alert (" Success ")); Get_each_total_broken (alert (" failed "));}) ; and it is not
get_each_total = function (callback) {var request; request = []; var url ; url = "http://otter.topsy.com/search.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d"; refund request. Push ($. GetJSON (URL, Function (Data) {})); Refund $. Then ($ (requests). Then (function () {callback ();}, function () (return warning ("There was an error in communicating with a remote library, try again in some");}); }; Get_each_total_broken = function (callback) {var request: request = []; Var url; url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q= Justin + bieber & window = d "; return request.push ($ .getJSON (url, function (data) {})) return $ then again ($ (requests). Then (function () {callback ();} , Function () (return warning ("a remote library Scope There was an error in communication with, try again in a few ");});}; $ (function () {Get_each_total (function () {alert (" Success "}); Get_each_total_broken (function () {alert ( As you can see, only the difference is in the previous two rows, where an anonymous function wraps the callback. Any information is good.
This piece of code:
return request. Push ($ .getJSON (URL, function (data) {})); Exits your work callback is never called. P.S. When you are saying , the only difference is that there is an anonymous job wrapping callback , you say that you are also passing the function in the first version of your code. That is not true; You are trying to pass in the warning ('whatever'); is coming back, which is undefined ! more details: Both your function ( get_each_total , & amp; get_each_total_broken ) Parameters expect to be a function. Trying to call this code as the function (later in callback () ). However, this line: get_each_total (warning ("success")); get_each_total does not pass a function. This is equivalent to: returning var = warning ("success"); Get_each_total (returnedFromAlert); So, basically, you are not going to do anything in your get_each_total function. You get success warning immediately, before get_each_total .
Comments
Post a Comment