Advertisement
uopspop

Untitled

Sep 23rd, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" >
  5. <meta http-equiv="expires" content="0">
  6. <title>GetAllResponseHeaders</title>
  7.  
  8. </head>
  9. <body>
  10.  
  11. <input type=button value="getAllResponseHeaders"
  12.  onclick="getAllRespBTN()">
  13. <div id="showPanel"></div>
  14.  
  15. <script>      
  16. var xhr = null;
  17.  
  18. function createXHR(){  
  19.   if( window.XMLHttpRequest ){  
  20.     xhr = new XMLHttpRequest();
  21.   }else if( window.ActiveXObject ){  
  22.     xhr = new ActiveXObject("Microsoft.XMLHTTP");
  23.   }
  24.        
  25.   return xhr;
  26. }
  27.  
  28. function stateChanged(){
  29.   //server端處理完畢了没
  30.   if (xhr.readyState == XMLHttpRequest.DONE ){
  31.     if (xhr.status == 200){
  32.         document.getElementById("showPanel").innerHTML = xhr.getAllResponseHeaders();
  33.     }else{
  34.         alert(xhr.status);
  35.     }
  36.   }
  37.   //request做成功了嗎
  38. }
  39.  
  40. function getAllRespBTN(){  
  41.   xhr = createXHR();
  42.   if( xhr == null ){
  43.     alert("Does not support Ajax...");  
  44.     return;
  45.   }  
  46.  
  47.   //設定好回呼函式
  48.   xhr.onreadystatechange = stateChanged;
  49.  
  50.   //建立好Get連接
  51.   var url = "GetAllResponseHeaders.jsp";
  52.   xhr.open("Get",url, true);  
  53.   //送出請求
  54.   xhr.send(null);
  55.  
  56. }
  57. </script>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement