1. var XMLHttpReq;  
  2. function createXMLHttpRequest() {  
  3.     try {  
  4.         XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");//IE高版本创建XMLHTTP  
  5.     }  
  6.     catch(E) {  
  7.         try {  
  8.             XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");//IE低版本创建XMLHTTP  
  9.         }  
  10.         catch(E) {  
  11.             XMLHttpReq = new XMLHttpRequest();//兼容非IE浏览器,直接创建XMLHTTP对象  
  12.         }  
  13.     }  
  14.   
  15. }  
  16. function sendAjaxRequest(url) {  
  17.     createXMLHttpRequest();                                //创建XMLHttpRequest对象  
  18.     XMLHttpReq.open("post", url, true);  
  19.     XMLHttpReq.onreadystatechange = processResponse; //指定响应函数  
  20.     XMLHttpReq.send(null);  
  21. }  
  22. //回调函数  
  23. function processResponse() {  
  24.     if (XMLHttpReq.readyState == 4) {  
  25.         if (XMLHttpReq.status == 200) {  
  26.             var text = XMLHttpReq.responseText;  
  27.   
  28.             /** 
  29.              *实现回调 
  30.              */  
  31.             text = window.decodeURI(text);  
  32.             var cp = document.getElementById("cp");  
  33.             cp.innerHTML = "";  
  34.             var values = text.split("|");  
  35.             for (var i = 0; i < values.length; i++) {  
  36.                 var temp = document.createElement("option");  
  37.                 temp.text = values[i];  
  38.                 temp.value = values[i];  
  39.                 cp.options.add(temp);  
  40.             }  
  41.   
  42.   
  43.         }  
  44.     }  
  45.   

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-03-30
  • 2021-07-12
  • 2022-03-02
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2021-11-29
  • 2021-07-26
相关资源
相似解决方案