53 lines
1.3 KiB
HTML
53 lines
1.3 KiB
HTML
<!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>详情页面</title>
|
|
</head>
|
|
<body>
|
|
<img src="" alt="">
|
|
<h2></h2>
|
|
</body>
|
|
|
|
<script>
|
|
var url = location.search.split("=")[1]
|
|
|
|
function getData() {
|
|
// 拿出手机 创建一个新的ajax对象
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
// 输入号码
|
|
// 网址! 是后端给我们的,而且不止一个,每一个网址都有一个具体的功能
|
|
xhr.open("GET", `http://127.0.0.1:3000/api/index/info?url=${url}`)
|
|
|
|
// 拨号
|
|
xhr.send();
|
|
|
|
// 状态监听
|
|
xhr.onreadystatechange = function () {
|
|
if (xhr.readyState == 4) {
|
|
if (xhr.status == 200) {
|
|
var data = JSON.parse(xhr.responseText)
|
|
console.log(data);
|
|
|
|
render(data.result)
|
|
} else {
|
|
alert("当前请求失败,请稍后再试")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function render(res) {
|
|
console.log(res);
|
|
document.querySelector("h2").innerText = res.title
|
|
document.querySelector("img").src = res.backImg
|
|
}
|
|
|
|
|
|
getData()
|
|
</script>
|
|
</html> |