JQuery Ajax request

1. Overview of Ajax:

It is a technology to send an asynchronous request to the server and receive an asynchronous response in a web application. The main process of implementation is:

1. JS in the browser sends a request to the server

2. The server sends the response information to the JS in the browser

3. JS operates part of the browser through DOM

Supplement: DOM (Document Object Model, Document Object Model). It is a platform- and language-independent application programming interface (API) that can dynamically access programs and scripts.

2. Overview of JQuery Ajax:

Use Ajax technology in the JQuery environment to realize partial update of web content without reloading all pages.

Supplement: Combined with JQuery, it is more convenient to update the page than simply using Ajax.

3. Parameters commonly used in JQuery technology:

1. url: Specifies the URL to be sent

2. data: the data to be sent to the server

3. dataType: The data type of the expected server response

4. asybc: asynchronous or synchronous request, the value is TRUE or FALSE, the default is TRUE

5. success(): The function that runs when the request succeeds

6. beforeSend(xhr): send

Supplement: The full name of xhr is XMLHttpRequest, which is used to exchange data with the server. It is the object on which the ajax function is implemented. Ajax in jquey is the encapsulation of xhr.

The XMLHttpRequest object provides full access to the HTTP protocol, including the ability to make POST and HEAD requests as well as ordinary GET requests. XMLHttpRequest can return the web server's response synchronously or asynchronously, and can return content in the form of text or a DOM document.

7. cache: Boolean value, indicating whether the browser caches the requested page. The default is true.

8. complete(xhr,status): The function that runs when the request is completed (called after the request succeeds or fails, that is, after the success() and error() functions).

9. contentType: The content type used when sending data to the server.

Default: "application/x-www-form-urlencoded".

10. context: linked to the context of the backend, which is equivalent to "this" in the callback function of ajax.

11. dataFilter(data,type): filter, a function to process the original response data of XMLHttpRequest.

12. globl: specifies whether the request of the ajax event is triggered globally, and the default value is true.

13. ifModified: Specifies whether the request succeeds only when the response has changed since the last request. The default is false.

14. jsonp: Rewrite the string of the callback function in a jsonp.

15. jsonpCallback: Specify the name of the callback function in a jsonp.

16. Specify the password used in the HTTP access authentication request.

17. processData: Specifies whether the data sent through the request is converted into a query string. The default is true.

18. scriptCharset: Specifies the requested character set.

19. timeout: Set the local request timeout.

20. Traditional: Specifies whether to use the traditional style of parameter serialization.

21. type: Specifies the type of request (GET or POST).

22. username: Specifies the username used in the HTTP access authentication request.

23. password: Specifies the password used in the HTTP access authentication request.

24. xhr: A function used to create an XMLHttpRequest object.

Five, the difference between ajax and axios in jquery:

1. Ajax is the encapsulation of native XHR (xmlHttpReqest), and axios is a Promise-based HTTP library.

2. Ajax technology realizes the refresh of partial data, and axios realizes the encapsulation of ajax.

To put it simply: jQuery encapsulates the request technology into ajax, ajax technology realizes the partial data refresh of the web page, and further encapsulates ajax into axios through promis.

Supplement: With ajax, why create axios:

Axios is more suitable for data requests in front-end mvvm mode.

Ajax is more suitable for data requests of MVC structure projects.

Guess you like

Origin blog.csdn.net/zhan_qian/article/details/128359853