頁面調用ajax

  1. 調用AJAX
  2. //組織基本調用信息
  3.     function callAjax() {
  4.       var url = "http://localhost:8000/sample/AjaxData.jsp";
  5.       var callBack = AjaxResponseprocess;
  6.       executeXhr(callBack, url);
  7.     }
  8. //調用Ajax
  9.     function executeXhr(callBack, url) {
  10.       if (window.XMLHttpRequest) {
  11.         req = new XMLHttpRequest();
  12.         req.onreadystatechange = callBack;
  13.         req.open("GET", url, true);
  14.         req.send(null);
  15.       } else if (window.ActiveXObject) {
  16.         req = new ActiveXObject("Microsoft.XMLHTTP");
  17.         if (req) {
  18.           req.onreadystatechange = callBack;
  19.           req.open("GET", url, true);
  20.           req.send();
  21.         }
  22.       }
  23.     }
  24.     //響應回調函數
  25.     function AjaxResponseprocess() {
  26.       if (req.readyState == 4) {
  27.         if (req.status == 200) {
  28.           var returnstr = req.responseText;
  29.           var list = returnstr.split("/n");
  30.           for (var i = 0; i < list.length; i++)
  31.           {
  32.            var obj = new objItem(list[i].substring(0, 4), list[i].substring(5, 10));
  33.            objItemList[objItemList.length] = obj;
  34.         var newElem = document.createElement("option"); 
  35.         newElem.text = list[i]; 
  36.         newElem.value = list[i]; 
  37.         document.getElementById("ctrlList").options.add(newElem); 
  38.           }
  39.           document.getElementById("ArrayCount").value = objItemList.length;
  40.           document.getElementById("ListCount").value = list.length;
  41.         }
  42.       }
  43.     }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章