Home  >  Article  >  Web Front-end  >  What is the difference between axios and jquery

What is the difference between axios and jquery

WBOY
WBOYOriginal
2022-04-20 18:18:022848browse

Difference: 1. axios is an asynchronous request framework, used to encapsulate the underlying XMLHttpRequest, while jquery is a JavaScript library, which just encapsulates dom operations by the way; 2. axios is based on promise objects, and promises can be used Methods in objects, and jquery is not based on promise objects.

What is the difference between axios and jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

What is the difference between axios and jquery

1. axios is a dedicated asynchronous request framework, used to encapsulate the underlying XMLHttpRequest, similar to the previous ajax, while jquery: just encapsulated by the way DOM operation

2. Axios is based on the promise object (promise), that is, you can use the methods in the promise object (then, catch, finally)

Every time an axios request is sent, the return value For the promise object

axios().then()
axios.all()

jquery is not based on the promise object

3. Axios re-encapsulates the response data

 $.ajax({
     url:'',
     success:function(data){
         data->java后台返回的数据,但是不同的人员对后台的数据封装不同
     }
 })
 axios().then(response=>{
     //response:是axios二次封装的相应对象
     response:{
         status
         statusText
         data:
         config:请求的配置信息
     }
 })

4. Axios sends a post request carrying parameters, and the parameters are default Sent in the form of a json string, that is, the default format of the request header is: contentType: "application/json"

And the post method in ajax: the query string is sent by default, which means that the request header The default format is: contentType: "application/x-www-form-urlencoded"

     查询字符串  name=lisi&age=20
     json:{
         "name":"lisi",
         "age":20
     }
     json:前后台交互

Related video tutorial recommendations: jQuery video tutorial

The above is the detailed content of What is the difference between axios and jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn