May 2017
Intermediate to advanced
448 pages
10h 10m
English
Perhaps a more important aspect of jqXHR than the XMLHttpRequest interface, however, is that it also acts as a promise. In Chapter 11, Advanced Effects, you learned about deferred objects, which allow us to set callbacks to be fired when certain operations are complete. An Ajax call is an example of such operation, and the jqXHR object provides the methods we expect from a deferred object's promise.
Using the promise's methods, we can rewrite our $.ajax() call to replace the success and error callbacks with an alternate syntax:
$.ajax({ url: 'https://api.github.com/search/repositories', dataType: 'jsonp', data: { q: $('#title').val() }, timeout: 10000,}).then((json) => { var output = json.data.items.map(buildItem); output = ...Read now
Unlock full access