Skip to content

Instantly share code, notes, and snippets.

@michaelschofield
Created May 2, 2014 13:24
Show Gist options
  • Save michaelschofield/113c28fa8687a9db8319 to your computer and use it in GitHub Desktop.
Save michaelschofield/113c28fa8687a9db8319 to your computer and use it in GitHub Desktop.
Multiple AJAX and JSON Requests, One Callback
// From David Waslh: http://davidwalsh.name/jquery-ajax-callback
$.when(
$.getScript('/media/js/wiki-min.js?build=21eb633'),
$.getJSON('https://developer.mozilla.org/en-US/demos/feeds/json/featured/')
).then(function(a, b) { // or ".done"
// Yay, stuff loaded and now we can do something!
});
// With Traditional AJAX Request
$.when(
$.getScript('/media/js/wiki-min.js?build=21eb633'),
$.getJSON('https://developer.mozilla.org/en-US/demos/feeds/json/featured/'),
$.get('/')
).then(function(a, b, c) {
console.log(a, b, c);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment