SHOW:
|
|
- or go back to the newest paste.
| 1 | var deferred = $.Deferred(); | |
| 2 | ||
| 3 | deferred.then(function(data){
| |
| 4 | // new deferred that we will be returning | |
| 5 | var deferred = $.Deferred(); | |
| 6 | if (data.success == true) {
| |
| 7 | deferred.resolveWith(data.result); | |
| 8 | } | |
| 9 | else {
| |
| 10 | deferred.rejectWith(data.error); | |
| 11 | } | |
| 12 | // any following chained methods will affect this returned deferred object | |
| 13 | return deferred; | |
| 14 | }).then( | |
| 15 | // done callback | |
| 16 | - | function(data){
|
| 16 | + | function(result){
|
| 17 | console.log("Resolved!");
| |
| 18 | - | console.dir(data); |
| 18 | + | console.dir(result); |
| 19 | }, | |
| 20 | // fail callback | |
| 21 | - | function(){
|
| 21 | + | function(error){
|
| 22 | console.log("Rejected!");
| |
| 23 | console.dir(error) | |
| 24 | } | |
| 25 | ); | |
| 26 | ||
| 27 | var json = $.getJSON("/foo");
| |
| 28 | json.done(deferred.resolveWith); |