How can I pass parameters to the XMLHttpRequest Object?
function setGUID(aGUID) {
var xhReq = new XMLHttpRequest();
xhReq.open(\"POST\", \"ClientS
There's a lot of tutorials about "xmlhttprequest post" on the internet. I just copy one of then:
Take a look:
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
https://www.google.com/search?q=xmlhttprequest+post
var http = new XMLHttpRequest();
var url = "url";
var params = JSON.stringify({ appoverGUID: approverGUID });
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/json; charset=utf-8");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
This way works for me.
var data = new FormData();
data.append('parameter_1', 'value parameter 1');
data.append('parameter_2', 'value parameter 2');
...
var xhr = new XMLHttpRequest();
xhr.open('POST', 'URL', true);
xhr.onload = function () {
console.log(this.responseText);
};
xhr.send(data);
Just remove these two lines (which are not allowed to set these headers):
http.setRequestHeader("Content-type", "application/json; charset=utf-8");
xmlHttp.setRequestHeader("Connection", "close");