Javascript – POST Request (Javascript)


How do you make a simple POST request in Javascript without using a forms and without posting back?

Best Solution

Though I am taking the code sample from @sundeep answer, but posting the code here for completeness

var url = "sample-url.php";
var params = "lorem=ipsum&name=alpha";
var xhr = new XMLHttpRequest();"POST", url, true);

//Send the proper header information along with the request
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");