1var xhr = new XMLHttpRequest();
2var params = 'field1='+postfield1+'&field2='+postfield2;
3xhr.open('POST', 'http://exmaple.com', true);
4
5//Send the proper header information along with the request
6xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
7
8xhr.onload = function() {//Call a function when the state changes.
9 if(xhr.status == 200) {
10 alert(this.responseText);
11 }
12}
13xhr.send(params);
1var xhr = new XMLHttpRequest();
2xhr.open("POST", '/url', true);
3xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
4
5xhr.onreadystatechange = function() { // Call a function when the state changes.
6 if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
7 // Request finished. Do processing here.
8 }
9}
10xhr.send("name=Hello&id=world");