JavaScript XMLHttpRequest

XMLHttpRequest is a JavaScript object type that can be used to retrieve a resource via a URL. Despite the Http in the name of the type, an XMLHttpRequest object can be used to retrieve resources via various protocols including the

First, create an instance of XMLHttpRequest:

var req = new XMLHttpRequest();

Add any necessary event listeners to the request:

req.addEventListener("load", function(ev){alert("status=" + req.status);});
req.addEventListener("error", function(ev){alert("handle error");});

To send a GET request:

var url = "";"GET", url, true);

To send a POST request:

var url = ";"POST", url, true);
var formData = new FormData();
formData.append("param", "value");