加载内容到元素中:

node2:/django/mysite/news/templates#cat displaytestxhr.html
<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8" />
      <title>Listing 10.3</title>
      <link rel="stylesheet" href="../css/main.css"/>
   </head>
   <body>
   <body>
      <div id="aa">aaaaa</div>
      <div id="elem"></div>
      <div id="bb">bbbb</div>

      <script>
         var xhr;
         if (window.ActiveXObject) {
            xhr = new ActiveXObject('Microsoft.XMLHTTP');
         } else if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
         } else {
            throw new Error('Ajax is not supported by this browser');
         }

         xhr.onreadystatechange = function() {
            if (this.readyState === 4) {
               if (this.status >= 200 && this.status < 300) {
                  document.getElementById('elem').innerHTML = this.responseText;
               }
            }
         };

         xhr.open('GET','/testxhr/?a=11&b=22&c=53');
         xhr.send();
      </script>
   </body>
</html>

原文地址:https://www.cnblogs.com/hzcya1995/p/13348851.html