The difference between axios and ajax: 1. axios is a Promise-based HTTP library, while ajax is an encapsulation of native XHR; 2. ajax technology realizes the refresh of local data, while axios realizes the ajax Encapsulation.
The operating environment of this article: Windows 7 system, ECMAScript version 6, Dell G3 computer.
What is the difference between axios and ajax?
The difference, advantages and disadvantages between axios and ajax:
ajax:
1. What is ajax
## Ajax is an encapsulation of native XHR. In order to achieve We crossed over and added support for JSONP.
Asynchronous javascript and xml, ajax is not a new technology, but a combination of multiple technologies. It is used to quickly create dynamic pages and can update data without refreshing to improve user experience. experience.
2. The principle of ajax?
The client requests the ajax engine, and then the ajax engine requests the server. The server makes a series of responses and returns to the ajax engine. The ajax engine decides where to write the result to the client. Achieve data update without page refresh.3. Core object?
XMLHttpReques
4. What are the advantages and disadvantages of ajax?
Advantages 1. Update data without refreshing 2. Asynchronous communication with the server 3. Front-end and back-end load balancing 4. Widely supported based on standards 5. Separation of interface and application Disadvantages: 1. Ajax cannot use the Back and history functions, that is, for browsing damage to the organ mechanism. 2. Security issues Ajax exposes the details of interaction with the server 3. The support for the search engine is relatively weak 4. The exception handling mechanism that destroys the program 5. Violate the original intention of URL and resource positioning 6. Ajax does not support mobile devices well 7. Too much client code causes development costs
5. Ajax applicable scenarios . Form-driven interaction
.Deep-level tree navigation
.Fast User-to-user communication and response
. Insignificant scenarios such as voting, yes/no, etc.
. Scenarios of filtering data and manipulating related data
. Ordinary text input prompts and auto-complete scenarios
6. Ajax is not suitable for scenarios .Some simple forms
.Search
.Basic navigation
.Replace large amounts of text
.Manipulation of presentation
7, code
$.ajax({ type: 'POST', url: url, data: data, dataType: dataType, success: function () {}, error: function () {} });
8. Five steps of ajax request
1. Create XMLHttpRequest asynchronous object 2. Set callback function 3. Use The open method establishes a connection with the server 4. Send data to the server 5. Process different response statuses in the callback functionaxios :
1. What is axios
Axios is a platform based onPromise HTTP library can be used in browsers and node.js.
2. What features does axios have?
1. Create XMLHttpRequests in the browser
## 2. Create http requests in node.js
3. Support Promise API
4. Support interception of requests and responses
5. Convert request and response data
6. Cancel requests
7. Automatically convert to JSON data format
8. Client supports defense against XSRF
3. There are two ways to execute get request// 第一种方式 将参数直接写在url中axios.get('/getMainInfo?id=123')
.then((res) => {
console.log(res)
})
.catch((err) => {
console.log(err)
})// 第二种方式 将参数直接写在params中axios.get('/getMainInfo', { params: {
id: 123
}
})
.then((res) => {
console.log(res)
})
.catch((err) => {
console.log(err)
})
axios.post('/getMainInfo', {
id: 123})
.then((res) => {
console.log(res)
})
.catch((err) => {
console.log(err)
})
The difference between axios and ajax: axios is an encapsulation of ajax technology through Promise, just like jquery The encapsulation of ajax is the same. Simply put, ajax technology realizes the refreshing of local data, and axios realizes the encapsulation of ajax. Some axios have ajax, but some axios may not have ajax. In summary, axios is ajax. Ajax is more than axios.
Note: Traditional Ajax refers to XMLHttpRequest (XHR),
Axios and jQuer ajax are both encapsulation of AjaxRecommended learning: "ajax video tutorial"
The above is the detailed content of What is the difference between axios and ajax. For more information, please follow other related articles on the PHP Chinese website!

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.

Key goals and advantages of HTML5 include: 1) Enhanced web semantic structure, 2) Improved multimedia support, and 3) Promoting cross-platform compatibility. These goals lead to better accessibility, richer user experience and more efficient development processes.

The goal of HTML5 is to simplify the development process, improve user experience, and ensure the dynamic and accessible network. 1) Simplify the development of multimedia content by natively supporting audio and video elements; 2) Introduce semantic elements such as, etc. to improve content structure and SEO friendliness; 3) Enhance offline functions through application cache; 4) Use elements to improve page interactivity; 5) Optimize mobile compatibility and support responsive design; 6) Improve form functions and simplify verification process; 7) Provide performance optimization tools such as async and defer attributes.

HTML5transformswebdevelopmentbyintroducingsemanticelements,multimediacapabilities,powerfulAPIs,andperformanceoptimizationtools.1)Semanticelementslike,,,andenhanceSEOandaccessibility.2)Multimediaelementsandallowdirectembeddingwithoutplugins,improvingu

TherealdifferencebetweenusinganIDversusaclassinCSSisthatIDsareuniqueandhavehigherspecificity,whileclassesarereusableandbetterforstylingmultipleelements.UseIDsforJavaScripthooksoruniqueelements,anduseclassesforstylingpurposes,especiallywhenapplyingsty


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor
