Reference: https://www.kirupa.com/html5/making_http_requests_js.htm
Code:
var xhr = new XMLHttpRequest();
xhr.open('GET', "//ipinfo.io/json", true);
xhr.send();
xhr.addEventListener("readystatechange", processRequest, false);
function processRequest(e) {
document.getElementById('readyState').innerHTML = JSON.stringify(xhr.readyState);
document.getElementById('status').innerHTML = JSON.stringify(xhr.status);
document.getElementById('responseText').innerHTML = JSON.stringify(xhr.responseText.replace(/\n/g,'<br>'));
}
Ready State
Status Response Text (formatted):