54 lines
1.1 KiB
HTML
54 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>ajax</title>
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<ul>
|
|
|
|
</ul>
|
|
|
|
|
|
</body>
|
|
<!--<script>-->
|
|
<!-- function getData(res) {-->
|
|
<!-- console.log(res)-->
|
|
<!-- }-->
|
|
<!--</script>-->
|
|
<!--<script src="http://127.0.0.1:3000/api/json/info?call=getData"></script>-->
|
|
|
|
<script>
|
|
// 拿出电话
|
|
var ajax = new XMLHttpRequest();
|
|
// 输入号码
|
|
ajax.open("GET", "http://127.0.0.1:3000/api/json/index")
|
|
|
|
// 拨打电话
|
|
ajax.send()
|
|
|
|
// 对拨号的状态进行监听
|
|
ajax.onreadystatechange = function () {
|
|
if (ajax.readyState == 4) {
|
|
if (ajax.status == 200) {
|
|
var result = JSON.parse(ajax.responseText)
|
|
// var a = { name: 1 };
|
|
// console.log(JSON.parse(JSON.stringify(a)))
|
|
console.log(result.data)
|
|
result.data.newest.list.forEach(function (v){
|
|
document.querySelector("ul").innerHTML +=
|
|
`<li>
|
|
<img src="${v.preview}" alt="">
|
|
</li>`
|
|
})
|
|
} else {
|
|
console.log("请求错误")
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
</script>
|
|
</html> |