topical media & game development

talk show tell print

professional-javascript-16-CrossBrowserXMLHttpRequestExample.htm / htm

          <title>XML HTTP Request Example</title>
          <script type="text/javascript">
                  if (typeof XMLHttpRequest == "undefined" && window.ActiveXObject) {
                      function XMLHttpRequest() {
                          var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
                                               "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                          for (var i=0; i < arrSignatures.length; i++) {
                              try {
                                  var oRequest = new ActiveXObject(arrSignatures[i]);
                                  return oRequest;
                              } catch (oError) {
                          throw new Error("MSXML is not installed on your system.");               
                  function getServerInfo() {
                          var oRequest = new XMLHttpRequest();
                "get", "example.txt", false);
                          alert("Status is " + oRequest.status + " (" + oRequest.statusText + ")");
                          alert("Response text is: " + oRequest.responseText);
          <p>Click the button to make a call to the server using an XML HTTP request.
          This example works in all browsers that support an XML HTTP request object.</p>
          <input type="button" onclick="getServerInfo()" value="Get Server info" />

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.