What are Deferred objects and promises in jQuery?
{ "n": 1 }
{ "n": 2 }
<p>Page</p>
$.when($.getJSON('a.json'), $.getJSON('b.json')).done(function (a, b) {
console.log('Sum: ' + (a[0].n + b[0].n));
});
Console output
Sum: 3
Learn more about the similar topics:
| Tutorials |
|---|
| jQuery load() Method |
| jQuery Ajax: ajax(), get(), post() and getJSON() |
| jQuery Deferred, Promises and $.when() |
| Exercises & Assignments |
|---|
| Write jQuery code to load JSON data with Ajax and show it in a list |
| Write jQuery code to submit a form with Ajax |