node-XMLHttpRequest icon indicating copy to clipboard operation
node-XMLHttpRequest copied to clipboard

How do you make a synchronous request?

Open wle8300 opened this issue 11 years ago • 1 comments

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)

wle8300 avatar Dec 25 '13 17:12 wle8300

the 3rd param ("async") to xhr.open should be false (it is true by default): xhr.open("GET", URI, false);

arolson101 avatar Feb 15 '15 22:02 arolson101