Chapter 7. Communicating with the server
This chapter covers
- The server’s role in an SPA environment
- How MV* frameworks communicate with the server
- Handling results with callback functions and promises
- Consuming RESTful services
In chapter 1, you learned how the adoption of the XMLHttpRequest (XHR) API and the AJAX movement eventually led to the emergence of SPAs. After XHR was supported in the browser—as a COM component at first and then natively—developers could use it to asynchronously load both the application’s scaffolding and its data without refreshing the page. This opened many new avenues for the ways that web pages could be constructed.
Until now, you’ve been focusing on creating the SPA itself. In doing so, you’ve used XHR to dynamically retrieve the templates used to construct your views but restricted the data in your sample applications to local stub data. In this chapter, you’ll take another important step forward. You’re going to move the source data to the server and learn how to remotely access it from your SPA.