The difference between axios and ajax in jquery: 1. axios is an encapsulation of ajax technology through promise, while jquery encapsulates the request technology into ajax; 2. axios is a Promise-based HTTP library, and ajax is an encapsulation of native XHR.
The operating environment of this tutorial: windows10 system, jquery3.6.0 version, Dell G3 computer.
What is the difference between axios and ajax in jquery?
The difference between axios and ajax:
axios is a Promise-based HTTP library, while ajax is Encapsulation of native XHR;
ajax technology realizes the refresh of local data, and axios realizes the encapsulation of ajax.
axios is an encapsulation of ajax technology through promise, just like JQuery implements ajax encapsulation.
To put it simply: ajax technology realizes partial data refresh of web pages, and axios realizes the encapsulation of ajax. In other words, jQuery encapsulates the request technology into ajax, and through promise, ajax is encapsulated into axios. Axios is ajax, and ajax is more than just axios.
With ajax, why should we use axios?
In the current front-end mvvm mode, axios is more suitable for data requests.
Extended knowledge:
ajax definition
In short, AJAX does not reload the entire web page Load data through the background and display it on the web page
jQuery encapsulates native ajax for us. Now we only need a simple line of code to implement the AJAX function.
1. Underlying interface
$.ajax({ url:'', //请求地址 method:'', //请求方式 data:{}, //传参 无参可不写 success:function(res){ //请求成功的回调函数 }, error:function(err){ //请求失败的回调函数 }, })
2. Shortcut
$.get(url,data,function(res){}) $.post(url,data,function(res){})
Usage of axios request
Axios is a promise-based ( Promise is a solution for asynchronous programming) HTTP library, which can be used in browsers and node.js
jQuery ajax:
itself is for MVC programming and does not conform to the current front-end MVVM
is developed based on native XHR. The architecture of XHR itself is not clear. There is already an alternative to fetch
The whole JQuery project is too big. It is very awkward to introduce the entire JQuery just using ajax. Reasonable (adopting a personalized packaging solution and not being able to enjoy CDN services)
Native use of axios:
axios({ url:'http://47.93.206.13:8002/user/login', // baseURL:'http://47.93.206.13:8002', method:'post', // params: 用于get请求 data:{ //用于post请求 username:'admin1', password:'123321' } }).then((res) => { console.log(res); })
axios shortcut method:
/ 引入 let axios=require('axios')//到当前node_modules找,找不到再往上找 // 封装写法 axios.get('http://47.107.65.238:8888/index/article/pageQuery?page=1&pageSize=10') .then(function (response) { console.log(response); })
Video tutorial recommendation: jQuery video tutorial
The above is the detailed content of What is the difference between axios and ajax in jquery. For more information, please follow other related articles on the PHP Chinese website!

Using ID selectors is not inherently bad in CSS, but should be used with caution. 1) ID selector is suitable for unique elements or JavaScript hooks. 2) For general styles, class selectors should be used as they are more flexible and maintainable. By balancing the use of ID and class, a more robust and efficient CSS architecture can be implemented.

HTML5'sgoalsin2024focusonrefinementandoptimization,notnewfeatures.1)Enhanceperformanceandefficiencythroughoptimizedrendering.2)Improveaccessibilitywithrefinedattributesandelements.3)Addresssecurityconcerns,particularlyXSS,withwiderCSPadoption.4)Ensur

HTML5aimedtoimprovewebdevelopmentinfourkeyareas:1)Multimediasupport,2)Semanticstructure,3)Formcapabilities,and4)Offlineandstorageoptions.1)HTML5introducedandelements,simplifyingmediaembeddingandenhancinguserexperience.2)Newsemanticelementslikeandimpr

IDsshouldbeusedforJavaScripthooks,whileclassesarebetterforstyling.1)Useclassesforstylingtoallowforeasierreuseandavoidspecificityissues.2)UseIDsforJavaScripthookstouniquelyidentifyelements.3)Avoiddeepnestingtokeepselectorssimpleandimproveperformance.4

Classselectorsareversatileandreusable,whileidselectorsareuniqueandspecific.1)Useclassselectors(denotedby.)forstylingmultipleelementswithsharedcharacteristics.2)Useidselectors(denotedby#)forstylinguniqueelementsonapage.Classselectorsoffermoreflexibili

IDsareuniqueidentifiersforsingleelements,whileclassesstylemultipleelements.1)UseIDsforuniqueelementsandJavaScripthooks.2)Useclassesforreusable,flexiblestylingacrossmultipleelements.

Using a class-only selector can improve code reusability and maintainability, but requires managing class names and priorities. 1. Improve reusability and flexibility, 2. Combining multiple classes to create complex styles, 3. It may lead to lengthy class names and priorities, 4. The performance impact is small, 5. Follow best practices such as concise naming and usage conventions.

ID and class selectors are used in CSS for unique and multi-element style settings respectively. 1. The ID selector (#) is suitable for a single element, such as a specific navigation menu. 2.Class selector (.) is used for multiple elements, such as unified button style. IDs should be used with caution, avoid excessive specificity, and prioritize class for improved style reusability and flexibility.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
