fetch axios ajax的区别

2018-07-09  本文已影响0人  HowlEagle101Div

JQ ajax

$.ajax({
 type: 'POST',
 url: url,
 data: data,
 dataType: dataType,
 success: function () {},
 error: function () {}
});

优缺点:

axios

axios({
    method: 'post',
    url: '/user/12345',
    data: {
        firstName: 'Fred',
        lastName: 'Flintstone'
    }
})
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
});

优缺点:

fetch

try {
  let response = await fetch(url);
  let data = response.json();
  console.log(data);
} catch(e) {
   console.log("Oops, error", e);
}

优缺点:

上一篇 下一篇

猜你喜欢

热点阅读