4 回答

TA貢獻1831條經驗 獲得超4個贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <script type="text/javascript"> //定義XmlhttpRequest對象 var xmlrequest; //完成對對象XmlHttpRequest對象的初始化 function createXmlHttpRequest(){ if(window.XMLHttpRequest){ //DOM 2瀏覽器 xmlrequest = new XMLHttpRequest(); }else if(window.ActiveXObject){ //IE 瀏覽器 try{ xmlrequest = new ActiveXOPbject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlrequest = new ActiveXObject("Microsoft.XMlHTTP"); }catch(e){
} } } } //事件處理函數,當下拉列表選擇改變時,觸發改事件 function change(id){ //初始化XMLHttpRequest對象 createXmlHttpRequest(); //設置請求響應的URL var url = "second.jsp?id="+id; //打開與服務器響應地址的連接xmlrequest.open(method,url,async,user,password) xmlrequest.open("POST",url,true); //設置請求頭(Post必須設置,GET方式不需要) xmlrequest.setRequestHeader("Context-Type","application/x-www-form-urlencoded"); //設置處理響應的回調函數,此函數processResponse是自己定義的 xmlrequest.onreadystatechange = processResponse; //發送請求 xmlrequest.send(null); } //定義處理響應的回調函數 function processResponse(){ //響應完成且響應正常 if(xmlrequest.readyState == 4){ if(xmlrequest.status == 200){ //信息已經成功返回,開始處理信息 var headers = xmlrequest.getAllResponseHeaders(); //通過警告框輸出相應頭 alert("相應頭的類型 "+ typeof headers + "\n" + headers); //在頁面輸出所有的相應頭 document.getElementById("output").innerHTML = headers; }else{ //頁面不正常 window.alert("您所請求的頁面異常。"); } } } </script> |
- 4 回答
- 0 關注
- 1753 瀏覽
添加回答
舉報