Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between axios and ajax?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What is the difference between axios and ajax, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

The difference between axios and ajax: 1. Axios is a HTTP library based on Promise, while ajax encapsulates native XHR; 2. Ajax technology refreshes local data, while axios encapsulates ajax.

This article operating environment: windows7 system, ECMAScript version 6, Dell G3 computer.

What is the difference between axios and ajax?

The differences between axios and ajax and their advantages and disadvantages:

Ajax:

1. What is ajax

Ajax is an encapsulation of native XHR, which adds support for JSONP in order to achieve our cross-cutting goal.

Asynchronous javascript and xml,ajax is not a new technology, but a combination of technologies used to quickly create dynamic pages, can achieve no refresh update data to improve the user 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. The implementation page does not refresh and update the data.

3. Core object?

XMLHttpReques

4. Advantages and disadvantages of ajax?

Advantages

1. Update data without refreshing.

2. Communicate with the server asynchronously

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 Back and history functions, that is, the destruction of the browser mechanism.

2. Security issues ajax exposes the details of interaction with the server

3. The support for the recovery engine is relatively weak.

4. The exception handling mechanism of breaking the program.

5. Against the original intention of URL and resource positioning.

6. Ajax does not support mobile devices very well.

7. Too much client code causes the cost of development

5. Applicable scenarios for Ajax

. Form-driven interaction

. Deep tree navigation

. Fast communication response between users and users

. Innocuous scenes such as voting, yes/no, etc.

. Scenarios where data is filtered and manipulated

. Normal text input prompts and auto-completed scenarios

6. Ajax is not suitable for scenarios.

. A partially simple form

. Search

. Basic navigation

. Replace a large number 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 an XMLHttpRequest asynchronous object

two。 Set callback function

3. Use the open method to establish a connection with the server

4. Send data to the server

5. Deal with different response states in the callback function

Axios:

1. What is axios

Axios is a Promise-based HTTP library that can be used in browsers and node.js.

2. What are the features of axios?

1. Create a XMLHttpRequests in the browser

2. Create a http request in node.js

3. Support Promise API

4. Support interception of requests and responses

5. Conversion request and response data

6. Cancel the request

7. Automatically convert to JSON data format

8. The client supports defense against XSRF

3. There are two ways to execute a get request

/ / the first way is to write parameters directly in url axios.get ('/ getMainInfo?id=123'). Then ((res) = > {console.log (res)}). Catch ((err) = > {console.log (err)}) / / the second way is to write parameters directly in params axios.get ('/ getMainInfo') {params: {id: 123}}) .then ((res) = > {console.log (res)}) .catch ((err) = > {console.log (err)})

4. Execute the post request. Pay attention to the input parameters of the post request, which need not be written in the params field. This place should be different from the second method of the get request.

Axios.post ('/ getMainInfo', {id: 123}) .then ((res) = > {console.log (res)}) .catch ((err) = > {console.log (err)})

The difference between axios and ajax:

Axios is a kind of encapsulation of ajax technology through Promise, just like the encapsulation of ajax by jquery. To put it simply, ajax technology realizes the refresh of local data, axios realizes the encapsulation of ajax, some ajax of axios has, some axios of ajax may not have, in a word, axios is ajax,ajax not only axios.

Note: traditional Ajax refers to XMLHttpRequest (XHR)

Both axios and jQuer ajax encapsulate Ajax

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report