Created
September 30, 2015 18:03
-
-
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
This file contains hidden or 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
// 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