59 lines
1.3 KiB
HTML
59 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
|
|
</head>
|
|
<body>
|
|
<ul>
|
|
</ul>
|
|
</body>
|
|
<!--<script>-->
|
|
<!-- function dnkjdn(res) {-->
|
|
<!-- console.log(res)-->
|
|
<!-- }-->
|
|
<!--</script>-->
|
|
<!--<script src="http://127.0.0.1:3000/api/index?callback=dnkjdn"></script>-->
|
|
<script>
|
|
// 前端 http://localhost:63342/2020-08-17/ajax.html
|
|
// 后端 http://127.0.0.1:3000/api/index
|
|
// 域名,端口,协议
|
|
|
|
// 拿出电话
|
|
var http = new XMLHttpRequest();
|
|
// GET, POST, PUT, DELETE, OPTION
|
|
// 设置电话号码
|
|
http.open("GET","http://127.0.0.1:3000/api/zj");
|
|
// 拨打电话
|
|
http.send()
|
|
|
|
http.onreadystatechange = function () {
|
|
if(http.readyState == 4) {
|
|
if (http.status == 200) {
|
|
var res = JSON.parse(http.responseText)
|
|
console.log(res)
|
|
// res.data.forEach((val,index) => {
|
|
// document.querySelector("ul").innerHTML+=`<li>${val.title}</li>`
|
|
// });
|
|
} else {
|
|
alert("网络不好")
|
|
}
|
|
}
|
|
}
|
|
|
|
// ajax({
|
|
// method: 'GET',
|
|
// url: 'xxxx',
|
|
// success: function (res) {
|
|
//
|
|
// },
|
|
// error: function (erro) {
|
|
//
|
|
// }
|
|
// })
|
|
|
|
|
|
</script>
|
|
|
|
</html> |