ES2017: You can wrap the async code inside a function(say XHRPost) returning a promise( Async code inside the promise).
Then call the function(XHRPost) inside the for loop but with the magical Await keyword. :)
let http = new XMLHttpRequest();_x000D_
let url = 'http://sumersin/forum.social.json';_x000D_
_x000D_
function XHRpost(i) {_x000D_
return new Promise(function(resolve) {_x000D_
let params = 'id=nobot&%3Aoperation=social%3AcreateForumPost&subject=Demo' + i + '&message=Here%20is%20the%20Demo&_charset_=UTF-8';_x000D_
http.open('POST', url, true);_x000D_
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');_x000D_
http.onreadystatechange = function() {_x000D_
console.log("Done " + i + "<<<<>>>>>" + http.readyState);_x000D_
if(http.readyState == 4){_x000D_
console.log('SUCCESS :',i);_x000D_
resolve();_x000D_
}_x000D_
}_x000D_
http.send(params); _x000D_
});_x000D_
}_x000D_
_x000D_
(async () => {_x000D_
for (let i = 1; i < 5; i++) {_x000D_
await XHRpost(i);_x000D_
}_x000D_
})();
_x000D_