js-ajax技术

ajax 全称 Asynchronous Javascript And XML, 如何发起一次ajax请求呢?

//首先创建一个 XMLHttpRequest 对象
const xhr = XMLHttpRequest();
xhr.onload = function() {
  if (xhr.status >=200 && xhr.status < 300) {
    // 请求成功处理
    console.log(xhr.responseText);
  } else { 
    // 请求失败
    console.log(xhr.status);
  }
}

猜你喜欢

转载自blog.csdn.net/qq_39406792/article/details/82533356
今日推荐