Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created September 30, 2015 18:03
Show Gist options
  • Save al-the-x/9758292e930b6ea9f072 to your computer and use it in GitHub Desktop.
Save al-the-x/9758292e930b6ea9f072 to your computer and use it in GitHub Desktop.
Example of jQuery.ajax in action for TIY-Durham/2015-FALL-FEE
// globals: jQuery, $
;(function(globals){ // IIFE
/**
* Magic Tracer Bullet!
*
* Log whatever `arguments` are passed to `tracer` to the `console`
* for inspection. Great when you don't know what a callback will
* receive as inputs or aren't sure you know.
*/
function tracer(){
console.log(arguments);
}
jQuery.ajax('octocat.json')
.then(tracer); // Fire that Magic Tracer Bullet!
jQuery.ajax('not-a-file.json')
.then(tracer); // Will this ever fire?
jQuery.ajax('octocat.json') // Returns jqXHR object...
.then(function(data, success, jqXHR){
// callback signature from http://api.jquery.com/jQuery.ajax/#jqXHR under `jqHXR.then`
});
// Remember: look don't touch...
})(window || module && module.exports || this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment