axios是通过promise实现对ajax技术的一种封装,就像jQuery实现ajax封装一样。
简单来说: ajax技术实现了网页的局部数据刷新,axios实现了对ajax的封装。
axios是ajax ajax不止axios。
axios代码示例如下:
axios({
url: 'http://wwww.xxx.com/user',
method: 'get',
//method:'post'
responseType: 'json', // 默认的
data: {
//'name':'gakki'
//'sex':'woman',
//'age':'18'
}
}).then(function (response) {
console.log(response);
console.log(response.data);
}).catch(function (error) {
console.log(error);
})
ajax代码示例如下:
$.ajax({
url: 'http://wwww.xxx.com/user',
type: 'get', //post
dataType: 'json',
data: {
//'name':'gakki'
//'sex':'woman',
//'age':'18'
},
success: function (response) {
console.log(response);
},
error: function (error) {
console.log(error);
}
})