Appendix B. Review of the XMLHttpRequest API
This appendix covers
- A review of the XMLHttpRequest API
- The building of an XHR data source module
In this appendix, you’ll review the low-level API for making a server call. In a real-world application, you’ll likely rely on your MV* framework for XHR calls if it has this capability built in or a helper library such as jQuery if it doesn’t. These frameworks and libraries often abstract away much of the boilerplate code and provide you with simple, easy-to-use methods instead. Even so, it’s good to have at least a general idea of what’s going on under the covers. That’s why I’ll stick with vanilla JavaScript here, so you can see basic XHR mechanics at work. I’ll also not be using RESTful calls here, just to keep things fairly straightforward.
When you hear someone talk about making an AJAX call, they’re usually talking about making an XHR call (XHR is short for XMLHttpRequest). AJAX (or Ajax) is short for Asynchronous JavaScript and XML and generally refers to using JavaScript to dynamically update a web page with the results of an XHR call. This section focuses solely on the XMLHttpRequest part of AJAX.