Answers

Question and Answer:

  Home  Expert JavaScript Developer

⟩ How can I request data from the server without reloading the page in the browser?

JavaScript code which is being present and loaded in client browser, can request for data from the web server using XMLHttpRequest object. XMLHttpRequest.open() method is used to open the connection, not to send the request to web server. But, use of the function XMLHttpRequest.send() sends the request in real time. Example code is given below as:

var oRequest = new XMLHttpRequest();

var sURL = "http://"+ self.location.hostname + "/hello/requested_file.htm";

oRequest.open("GET",sURL,false);

oRequest.setRequestHeader("User-Agent",navigator.userAgent);

oRequest.send(null)

if (oRequest.status==200) alert(oRequest.responseText);

else alert("Error executing XMLHttpRequest call!");

 211 views

More Questions for you: