Ajax difference and go into the details axios

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45734493/article/details/102500780

1. difference

axios is to realize a packaging of the art by ajax promise, as jQuery ajax achieve the same package.
In simple terms: ajax technology to achieve local data page refresh, axios package to achieve the ajax.
axios ajax ajax is more than axios.
Listed below code to compare:

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);
            }
        })

2. advantages and disadvantages:

ajax:

Itself is programmed for the MVC, MVVM does not meet the current wave of front-end
based on the native XHR development, XHR architecture itself is not clear, have an alternative to fetch
JQuery entire project is too large, simply have to use the introduction of the entire JQuery ajax very unreasonable (take personalized packaging solutions can not enjoy CDN service

axios:

Created from a node.js http request
support Promise API
client support to prevent CSRF
provides a number of concurrent requests interface (important, convenient for a lot of operations)

Guess you like

Origin blog.csdn.net/weixin_45734493/article/details/102500780