<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body></body>
<script>
// 步骤1:创建 ajax请求对象
const oajax = new XMLHttpRequest();
//步骤2:建立连接
oajax.open("GET", "json/userInfo.json", true);
//配置响应结果类型
oajax.responseType = "json";
//步骤3:发送请求
oajax.send();
//步骤4:检测状态获取响应结果
oajax.onreadystatechange = function () {
if (oajax.readyState === 4 && oajax.status === 200) {
console.log("获取响应结果", oajax.response);
}
};
</script>
</html>
Ajax网络请求:案例操作
最新推荐文章于 2024-07-04 16:37:43 发布