標籤:
var XMLHttpReq;function createXMLHttpRequest() { try { XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");//IE高版本建立XMLHTTP } catch(E) { try { XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");//IE低版本建立XMLHTTP } catch(E) { XMLHttpReq = new XMLHttpRequest();//相容非IE瀏覽器,直接建立XMLHTTP對象 } }}function sendAjaxRequest(url) { createXMLHttpRequest(); //建立XMLHttpRequest對象 XMLHttpReq.open("post", url, true); XMLHttpReq.onreadystatechange = processResponse; //指定響應函數 XMLHttpReq.send(null);}//回呼函數function processResponse() { if (XMLHttpReq.readyState == 4) { if (XMLHttpReq.status == 200) { var text = XMLHttpReq.responseText; /** *實現回調 */ text = window.decodeURI(text); var cp = document.getElementById("cp"); cp.innerHTML = ""; var values = text.split("|"); for (var i = 0; i < values.length; i++) { var temp = document.createElement("option"); temp.text = values[i]; temp.value = values[i]; cp.options.add(temp); } } }}
JavaScript ajax請求