An Assignmenton AJAX
An Assignmenton AJAX
The XMLHttpRequest object can be used to exchange data with a web server
behind the scenes. This means that it is possible to update parts of a web page,
without reloading the whole page.
In this case, the callback function should contain the code to execute when the
response is ready.
xhttp.onload = function() {
// What to do when the response is ready
}
Send a Request
To send a request to a server, you can use the open() and send() methods of
the XMLHttpRequest object:
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
Example
// Create an XMLHttpRequest object
const xhttp = new XMLHttpRequest();
// Send a request
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
Try it Yourself »
This means that both the web page and the XML file it tries to load, must be
located on the same server.
The examples on W3Schools all open XML files located on the W3Schools
domain.
If you want to use the example above on one of your own web pages, the XML
files you load must be located on your own server.
XMLHttpRequest Object Methods
Method Description