JS Coding Questions Logo
JS Coding Questions
#170💼 Interview💻 Code

How do you make synchronous HTTP request

Advertisement

728x90

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

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

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 85

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
170of476