Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" >
- <meta http-equiv="expires" content="0">
- <title>GetAllResponseHeaders</title>
- </head>
- <body>
- <input type=button value="getAllResponseHeaders"
- onclick="getAllRespBTN()">
- <div id="showPanel"></div>
- <script>
- var xhr = null;
- function createXHR(){
- if( window.XMLHttpRequest ){
- xhr = new XMLHttpRequest();
- }else if( window.ActiveXObject ){
- xhr = new ActiveXObject("Microsoft.XMLHTTP");
- }
- return xhr;
- }
- function stateChanged(){
- //server端處理完畢了没
- if (xhr.readyState == XMLHttpRequest.DONE ){
- if (xhr.status == 200){
- document.getElementById("showPanel").innerHTML = xhr.getAllResponseHeaders();
- }else{
- alert(xhr.status);
- }
- }
- //request做成功了嗎
- }
- function getAllRespBTN(){
- xhr = createXHR();
- if( xhr == null ){
- alert("Does not support Ajax...");
- return;
- }
- //設定好回呼函式
- xhr.onreadystatechange = stateChanged;
- //建立好Get連接
- var url = "GetAllResponseHeaders.jsp";
- xhr.open("Get",url, true);
- //送出請求
- xhr.send(null);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement