axios的原理

Axios 的本质是通过原生ajax,axios是基于HTTP客户端的promise,用于浏览器和nodeJS.

axios的特性:

1.从浏览器发送ajax请求
2.从nodeJS发送HTTP请求
3.支持promise Api
4.请求和相应的拦截
5.转换请求和响应数据
6.取消请求
7.json数据自动转换
8.客户端支持防止XSRF

ajax请求就是一个发送请求不需要跳转页面的js技术,请求模板如下:

var xhr = new XMLHttpRequest()//new一个HTTP请求
xhr.open('get','url')
//设置请求头 get方法不用设置
xhr.setRequestHeader('content-Type','application/x-www-form-urlencoded')
xhr.send()//发送请求
xhr.onreadystatechange = function(){
  if(xhr.readystate==4 && xhr.status == 200){
    console.log(xhr.responseText)
  }
}

猜你喜欢

转载自blog.csdn.net/Cinderellahh92/article/details/107730131
今日推荐