XMLHttpRequestQuestion: How can I request data from the server without reloading the page in the browser?
Answer:
JavaScript code loaded in the client browser can request additional data from the Web server using the
In this example, when you click the Send Request button, the browser
requests additional var oRequest = new XMLHttpRequest(); var sURL = "http://" + self.location.hostname + "/faq/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!");
In most modern browsers, the general syntax of the var oRequest = new XMLHttpRequest(); oRequest.open( method, URL, async )
The parameters
Note that the
Historical Note. In older browsers, e.g. in Microsoft Internet Explorer 6 or earlier, you might not be able to instantiate the
oRequest = new ActiveXObject("Msxml2.XMLHTTP"); oRequest = new ActiveXObject("Microsoft.XMLHTTP"); |
Copyright © 1999-2011, JavaScripter.net.