// 创建XMLHttpRequest对象
var xhr = new XMLHttpRequest();
// 配置请求
var method = 'GET';
var url = 'your-api-endpoint';
xhr.open(method, url, true); // 异步请求
// 设置回调函数
xhr.onreadystatechange = function () {
// 请求完成并且响应状态为200
if (xhr.readyState === 4 && xhr.status === 200) {
// 处理服务器响应的数据
var response = JSON.parse(xhr.responseText);
console.log(response);
}
};
// 发送请求
xhr.send();
Ajax流程
最新推荐文章于 2024-07-12 09:12:36 发布