<script>
function showLogin()
{
// 内容
}
setInterval("showLogin()","1000");
</script>
js自动调用执行
------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>数据交互</title>
<script src="__JS__/jquery.min.js"></script>
</head>
<body>
<table id='table-test'>
<tr>
<th>期数</th>
<th>code码</th>
<th>和值</th>
</tr>
</table>
</body>
<script>
//假设每隔5秒发送一次请求
window.onload = function () {
getApi();
}
function getApi() {
$.ajax({
url: 'http://www.xxx.com/xxx',
type: 'get',
dataType: 'json',
success: function (data) {
//方法中传入的参数data为后台获取的数据
// console.log(data.msg);
if(data.code == 1){
var data1 = data['data']['history'];
// console.log(data1);
var tr;
$.each(data1,function (index,item) {
//字符串转数组
var code = item['code'].split(',');
//数组转字符串:
var strCode = code.join(' ');
// console.log(strCode)
tr = '<td>'+item['issue']+'</td>'+'<td>'+strCode+'</td>'+'<td>'+item['sum']+'</td>';
$('#table-test').append('<tr>'+tr+'</tr>');
})
}else {
//设置请求api接口时间
setTimeout(getApi,5*1000);
}
}
})
}
</script>