So implementieren Sie eine teilweise automatische Aktualisierung der von der Schnittstelle erhaltenen Tabelleninformationen
胡行东
胡行东 2019-03-29 11:02:54
0
2
1121

html如下:


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<! -- <meta http-equiv="refresh" content="2"> -->
<script language="javascript" src="../JS/login.js"></script>
<link rel="stylesheet" href="../CSS/login .css" type="text/css">
</head>
<body onload="Login();">
 <div class="main">
 
 
 
 
 
  < ;div id="myDiv" class="table1box">
  
  
   <table id="table1" class="table1" border="1px">
    <tr>
     <th>信息< /th>
     <th>msg</th>
     <th>认证码</th>
    </tr>
    </div>
    </div>
   </table>
   
   
</body>
</html>



js如下:

function Login() {
 var. xmlhttp;
 if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
 } else {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 }

 xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState == 4 && xmlhttp. status == 200) {
   var datastr = xmlhttp.responseText;
   var dataobj = JSON.parse(datastr)
   let dataarr = [];
   for (let i in dataobj) {
    dataarr.push(dataobj[i]) ;
   }

   var table = document.getElementById("table1");
   var row = table.insertRow(table.rows.length);
   var c1 = row.insertCell(0);
   c1.innerHTML = dataarr[ 0];
   var c2 = row.insertCell(1);
   c2.innerHTML = dataarr[1];
   var c3 = row.insertCell(2);
   c3.innerHTML = dataarr[2];
  }
 }
xmlhttp.open("POST", "https://api.123321yun.com/api/user/login?username=test123&password=123456", true);
 xmlhttp.setRequestHeader("Content-type", "application/x -www-form-urlencoded");
 xmlhttp.send();
 
}

小白求帮忙

胡行东
胡行东

Antworte allen(1)
秋香姐家的小书童

1。确定要刷新 的元素 比如  id为 #cont

2。ajax不停的请求服务器(后端的逻辑自己写,什么条件下需要更新内容)

3。当请求到新的内容 就将元素#cont内容进行修改

就这么思路

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage