Created
May 10, 2011 02:34
-
-
Save chadhietala/963823 to your computer and use it in GitHub Desktop.
jQuery Deferred
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var demo = { | |
init : function(){ | |
var query = 'select * from music.artist.id where ids="289282"', | |
url = 'https://query.yahooapis.com/v1/public/yql?q=' | |
+ encodeURIComponent(query) +'&format=json&env=store%3A%2F%2Fdatatables.org' | |
+'%2Falltableswithkeys&callback=?&_maxAge=3000', | |
getIt = demo.getData(url) | |
.then(function(data){ | |
console.log(data); | |
}); | |
}, | |
getData : function(url){ | |
var dfr = $.Deferred(); | |
$.ajax({ | |
type: 'GET', | |
url: url, | |
dataType: 'json', | |
success: dfr.resolve | |
}); | |
return dfr.promise(); | |
}, | |
facebook : function(){ | |
var url = 'http://graph.facebook.com/umflint/posts?callback=?', | |
getIt2 = demo.getData(url) | |
.then(function(data){ | |
console.log(data); | |
}); | |
} | |
}; | |
$(document).ready(function(){ | |
demo.init(); | |
demo.facebook(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment