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 = "http://www.ExampleOnly.com/demo/env.php?query&param=value";
req.open("GET", url, true);
req.send(null);

To send a POST request:

var url = "http://www.ExampleOnly.com/demo/env.php;
req.open("POST", url, true);
var formData = new FormData();
formData.append("param", "value");
req.send(formData);