function postAjax(url, data, success) {
var params = typeof data == 'string' ? data : Object.keys(data).map(
function (k) { return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) }
).join('&');
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.onreadystatechange = function () {
if (xhr.readyState > 3 && xhr.status == 200) { success(xhr.responseText); }
};
xhr.setRequestHeader("Access-Control-Allow-Accept", "application/json");
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(params);
return xhr;
}
postAjax('http://localhost:5500/temp.php', 'p1=1&p2=Hello+World', function (data) { console.log(data); });