Skip to main content
InterviewHubPRO
Section Overview
Q174

Question 174 of 536

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

32%
JavaScript & V8 Internals (536 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

How do you make synchronous HTTP request

mid LevelMost AskedCode ExampleEvent LoopPrototypesHTTP & REST APIs

Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript.

javascript
  function httpGet(theUrl) {
    var xmlHttpReq = new XMLHttpRequest();
    xmlHttpReq.open("GET", theUrl, false); // false for synchronous request
    xmlHttpReq.send(null);
    return xmlHttpReq.responseText;
  }