Interviewer And Interviewee Guide

Expert Developer JavaScript Interview Question:

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

Submitted by: Administrator
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!");
Submitted by:

Read Online Expert Developer JavaScript Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.