topical media & game development

talk show tell print

professional-ajax-02-XMLHttp-Examples-XMLHttpExample1.htm / htm

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <title>XMLHttp Example 1</title>
      <script type="text/javascript"src="zxml.js"></script>
      <script type="text/javascript">
          function requestCustomerInfo() {
              var sId = document.getElementById("txtCustomerId").value;
              var oXmlHttp = zXmlHttp.createRequest();
    "get", "GetCustomerData.php?id=" + sId, true);
              oXmlHttp.onreadystatechange = function () {
                  if (oXmlHttp.readyState == 4) {
                      if (oXmlHttp.status == 200) {
                      } else {
                          displayCustomerInfo("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
          function displayCustomerInfo(sText) {
              var divCustomerInfo = document.getElementById("divCustomerInfo");
              divCustomerInfo.innerHTML = sText;
      <p>Enter customer ID number to retrieve information:</p>
      <p>Customer ID: <input type="text" id="txtCustomerId" value="" /></p>
      <p><input type="button" value="Get Customer Info" onclick="requestCustomerInfo()" /></p>
      <div id="divCustomerInfo"></div>

(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.