axios, fetch, ajax difference

The Jquery ajax

1 $.ajax({
2 type:"get",
3 url:"",
4 async:true,
5 data:{},
6 dataType:"",
7 success:function(){
8 }
9 });

type get in what way the data is get or POST
url required, the provisions of which the request is sent to the URL.
axync true / false, default tue asynchronous request, false synchronization. After the asynchronous request $ .ajax execution, will continue behind the ajax script, after the server returns data to trigger success callback success of that single thread. Synchronization requests: All requests are synchronized.
Optional data. Like past with server parameters when sending the request. When the post is generally carried requested user name or id.
dataType optional. Provision of data types expected response from the server.
The default implementation of intelligent judgment (xml, json, script or html).

Optional success. Implementation of data returned on success.
 

 

  

 Advantages and disadvantages:

XHR is based on the original development of the currently available alternative fetch. Itself against mvc programming model is not suitable for the current programming mode mvvm. jQuery itself is relatively large, simple to use ajax if you can own a package, or will affect the performance experience.

 axios解析

axios({
method: 'post',
url: '',
data: {}
})
.then(function (data) {
console.log(data);
}
特点:

Create XMLHttpRequest request from the browser.

node.js create http request.

Automatically converted to the data type json

Support promise API, the interface provides a number of concurrent requests.

Vue family bucket is one of the technology, require the use of npm install axios --save-dev in vue to install the dependencies.

fetch解析

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

Out xhr.

Es is the norm in new implementations.

More ground floor, provides a rich API.

.fetch no way to monitor the progress of native request, and XHR can.

 Summary
ajax to send back-end technology is the earliest request belonging to native js category, the core is using the XMLHttpRequest object, and a sequential use more words, prone callback hell.

ajax fetch can replace the known technique, is based on the object es6 Promise of design parameters in jQuery ajax Similarly, it is not to ajax further encapsulated, it belongs to the category of native js. Not using the XMLHttpRequest object.

axios not native js, its use need be installed, the client and server may be used, may intercept the request and the corresponding phase, based on the promise object.

Guess you like

Origin www.cnblogs.com/bgd150809324/p/11353553.html