- 调用AJAX
- //组织基本调用信息
- function callAjax() {
- var url = "http://localhost:8000/sample/AjaxData.jsp";
- var callBack = AjaxResponseprocess;
- executeXhr(callBack, url);
- }
- //调用Ajax
- function executeXhr(callBack, url) {
- if (window.XMLHttpRequest) {
- req = new XMLHttpRequest();
- req.onreadystatechange = callBack;
- req.open("GET", url, true);
- req.send(null);
- } else if (window.ActiveXObject) {
- req = new ActiveXObject("Microsoft.XMLHTTP");
- if (req) {
- req.onreadystatechange = callBack;
- req.open("GET", url, true);
- req.send();
- }
- }
- }
- //响应回调函数
- function AjaxResponseprocess() {
- if (req.readyState == 4) {
- if (req.status == 200) {
- var returnstr = req.responseText;
- var list = returnstr.split("/n");
- for (var i = 0; i < list.length; i++)
- {
- var obj = new objItem(list[i].substring(0, 4), list[i].substring(5, 10));
- objItemList[objItemList.length] = obj;
- var newElem = document.createElement("option");
- newElem.text = list[i];
- newElem.value = list[i];
- document.getElementById("ctrlList").options.add(newElem);
- }
- document.getElementById("ArrayCount").value = objItemList.length;
- document.getElementById("ListCount").value = list.length;
- }
- }
- }