1function httpGet(theUrl)
2{
3 var xmlHttp = new XMLHttpRequest();
4 xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
5 xmlHttp.send( null );
6 return xmlHttp.responseText;
7}
1window.onload = function(){
2 var request = new XMLHttpRequest();
3 var params = "UID=CORS&name=CORS";
4
5 request.onreadystatechange = function() {
6 if (this.readyState == 4 && this.status == 200) {
7 console.log(this.responseText);
8 }
9 };
10
11 request.open('POST', 'https://www.example.com/api/createUser', true);
12 request.setRequestHeader('api-key', 'your-api-key');
13 request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
14 request.send(params);
15}
16