zoukankan      html  css  js  c++  java
  • XMLHttpRequest实例

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
     5 <title>Document</title>
     6 <script type="text/javascript">
     7 var xmlhttp;
     8 function loadXMLDoc(url){
     9     xmlhttp = null;
    10     if(window.XMLHttpRequest){
    11         xmlhttp = new XMLHttpRequest();
    12     }else if(window.ActiveXObject){
    13         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    14     }
    15     if(xmlhttp!=null){
    16         xmlhttp.onreadystatechange = state_Change;
    17         xmlhttp.open("GET", url, true);
    18         xmlhttp.send(null);
    19     }else{
    20         alert("Your brower does not support XMLHTTP");
    21     }
    22 }
    23 function state_Change(){
    24     if(xmlhttp.readyState == 4){
    25         if(xmlhttp.status == 200){
    26             document.getElementById('A1').innerHTML = xmlhttp.status;
    27             document.getElementById('A2').innerHTML = xmlhttp.statusText;
    28             document.getElementById('A3').innerHTML = xmlhttp.responseText;
    29         }else{
    30             alert("Problem retrieving XML data:" + xmlhttp.statusText);
    31         }
    32     }
    33 }
    34 </script>
    35 </head>
    36 <body>
    37     <h2>Using the HttpRequest</h2>
    38     <p>
    39         <b>Status:</b>
    40         <span id = "A1"></span>
    41     </p>
    42     <p>
    43         <b>status text:</b>
    44         <span id = "A2"></span>
    45     </p>
    46     <p>
    47         <b>Response:</b>
    48         <br /><span id = "A3"></span>
    49     </p>
    50 
    51     <button onclick="loadXMLDoc('note.xml')">Get XML</button>
    52 </body>
    53 </html>
    <?xml version="1.0" encoding = "ISO-8859-1"?>
    <note>
        <to>George</to>
        <from>John</from>
        <heading>Reminder</heading>
        <body>Don't forget the meeting!</body>
    </note>
  • 相关阅读:
    html问题记录20180529
    html问题记录20180518
    html问题记录20180515
    Redis持久化--AOF
    Redis持久化--RDB
    Redis事件模型
    两个字符串的编辑距离-动态规划方法
    Reactor事件模型在Redis中的应用
    事件驱动模式--Reactor
    IO多路复用--总结
  • 原文地址:https://www.cnblogs.com/hell0x/p/5261065.html
Copyright © 2011-2022 走看看