JS and http requests - SelfishHellfish/JS_Ref GitHub Wiki

AJAX/XMLHttpRequest

useful for updating content on a webpage, e.g. via user refresh or with an automatic timer
var http = new XMLHttpRequest();
var url = 'http://jsonplaceholder.typicode.com/posts';
var method = 'GET';
http.open(method, url);
http.onreadystate = function() {if (http.readyState === XMLHttpRequest.Done && http.statys === 200) {console.log(JSON.parse(http.responseText))}};
http.send();

post request

var method = 'POST';
var data = 'title=some%20title';
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.send(data);
more
details