Side note: jQuery's deferred objectsĭeferred objects are jQuery's custom implementation of promises (before the Promise API was standardized). More information about promises: HTML5 rocks - JavaScript Promises. They provide a great abstraction and separation of your code. I am trying to return the value from the callback, as well as assigning the result to a local variable inside the function and returning that one, but none of those ways actually return the response (they all return undefined or whatever the initial value of the variable result is).Įxample of an asynchronous function that accepts a callback (using jQuery's ajax function) function foo() ĭescribing all the advantages that promise offer is beyond the scope of this answer, but if you write new code, you should seriously consider them. How can I return the response/result from foo? I have a function foo which makes an asynchronous request.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |