The XMLHttpRequest object is used to exchange data with a server.
To send a request to a server, we use the open() and send() methods of the XMLHttpRequest object:
xhttp.open("GET", "ajax_info.txt", true);
|open(method, url, async)||Specifies the type of request|
method: the type of request: GET or POST
url: the server (file) location
async: true (asynchronous) or false (synchronous)
|send()||Sends the request to the server (used for GET)|
|send(string)||Sends the request to the server (used for POST)|
GET is simpler and faster than POST, and can be used in most cases.
However, always use POST requests when:
A simple GET request:
xhttp.open("GET", "demo_get.html", true);