将jQuery的ajax、axios和fetch作个简单的比较,所谓仁者见仁智者见智,最终使用哪一个仍是自行斟酌javascript
1.jQuery ajax 前端
$.ajax({ type: 'POST', url: url, data: data, dataType: dataType, success: function () {}, error: function () {} });
优缺点:java
2.axiosnode
axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
优缺点:ios
3.fetchajax
try { let response = await fetch(url); let data = response.json(); console.log(data); } catch(e) { console.log("Oops, error", e); }
优缺点:编程
axios 是一个基于Promise 用于浏览器和 nodejs 的 HTTP 客户端,它自己具备如下特征:json