Skip to content

Instantly share code, notes, and snippets.

@DavidBruant
Created March 13, 2012 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidBruant/2030824 to your computer and use it in GitHub Desktop.
Save DavidBruant/2030824 to your computer and use it in GitHub Desktop.
// Boilerplate code to make the above work
var readyDef = new $.Deferred();
var readyP = readyDef.promise();
$(function(){ readyDef.resolve() });
$.when($.get('rss.xml'), readyP).then(function(rss){
// second argument purposefully ignored since I only care about synchronization
// build a document fragment
// append to the document
});
// Some students did:
$(function(){
var rssP = $.get('rss.xml') rssP.then(function(rss){
// build fragment
// append to DOM
});
});
/* Works as well, but the request isn't done until the document is
** ready which may be as late as the load event in old browsers
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment