Files
ClassContent/历届学生/fontendsix/每日课程/2021-11-05/index_2.html
2024-09-27 02:06:13 +08:00

51 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.staticfile.org/jquery/2.0.3/jquery.min.js"></script>
</head>
<body>
<img src="" alt="">
</body>
<script>
// 拿出手机 创建一个新的ajax对象
var xhr = new XMLHttpRequest();
// 输入号码
// 网址! 是后端给我们的,而且不止一个,每一个网址都有一个具体的功能
xhr.open("GET", "http://127.0.0.1:3000/api/index/hot")
// 拨号
xhr.send();
// 状态监听
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
// 序列化string转object/array
var data = JSON.parse(xhr.responseText)
data.result.forEach(v => {
console.log(v);
document.querySelector("ul").innerHTML += `<li>
<a href="${v.url}" target="_blank">
<img src="${v.img}" alt="">
<div class="title">${v.title}</div>
</a>
</li>`
});
} else {
alert("当前请求失败,请稍后再试")
}
}
}
</scrip>
</html>