Files
ClassContent/历届学生/18课程/class18_2/课程/2020-12-28/ajax.html
2024-09-27 02:06:13 +08:00

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>