node-XMLHttpRequest
node-XMLHttpRequest copied to clipboard
How do you make a synchronous request?
I assume it is by adding changing the argument to 'true', but it doesn't seem to be working. Do you know why?
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
data[i] = JSON.parse(this.responseText);
}
};
xhr.open("GET", URI, true);
xhr.send();
(This snippet is inside a for
loop)
the 3rd param ("async") to xhr.open should be false (it is true by default): xhr.open("GET", URI, false);