1.区别
axios是通过promise实现对ajax技术的一种封装,就像jQuery实现ajax封装一样。
ajax技术实现了网页的局部数据刷新,axios实现了对ajax的封装。
axios是ajax,ajax不止axios。
2.代码
axios
axios({ url: ‘/getUsers‘, method: ‘get‘, responseType: ‘json‘, // 默认的 data: { //‘a‘: 1, //‘b‘: 2, } }).then(function (response) { console.log(response); console.log(response.data); }).catch(function (error) { console.log(error); })
ajax
$.ajax({ url: ‘/getUsers‘, type: ‘get‘, dataType: ‘json‘, data: { //‘a‘: 1, //‘b‘: 2, }, success: function (response) { console.log(response); } })
3. 优缺点
ajax:
axios:
————————————————
原文链接:https://blog.csdn.net/qq_42942555/article/details/88400721
原文:https://www.cnblogs.com/banyouxia/p/13180140.html