You are previewing Eloquent JavaScript.

Eloquent JavaScript

Cover of Eloquent JavaScript by Marijn Haverbeke Published by No Starch Press
O'Reilly logo

The XMLHttpRequest API

When you click a link, submit a form, or in some other way encourage your browser to go to a new page, it will make an HTTP request and, if successful, show the newly loaded document. In typical situations, this is just what you want—it is how the Web traditionally works. Sometimes, however, a JavaScript program wants to communicate with the server without reloading the page.

To be able to do something like that, the program must make the HTTP request itself. Contemporary browsers provide an interface for doing this. As with opening new windows, this interface is subject to some restrictions—to prevent a script from doing anything scary, it is allowed to make HTTP requests only to the domain that the current page came from, ...

The best content for your career. Discover unlimited learning on demand for around $1/day.