Home >Web Front-end >Front-end Q&A >what is ajax callback

what is ajax callback

anonymity
anonymityOriginal
2019-05-08 10:36:475263browse

what is ajax callback

What is the callback of ajax?

callback is the callback function in ajax, which is a function called when the server responds to a request object. The browser will "call back" this function at a certain moment and process the ajax request results according to the five return statuses.

How to understand the callback function?

If you want to understand the callback function, you must first clearly understand the rules of the function. In JavaScript, functions are weird, but they are indeed objects. To be precise, a function is a Function object created using the Function() constructor. The Function object contains a string that contains the JavaScript code of the function. If you are coming from C or Java, this may seem strange, how can the code be a string? But with javascript, this is commonplace. The distinction between data and code is blurry.

Traditional functions input data in the form of parameters and use return statements to return values. Theoretically, there is a return statement at the end of the function, which is structurally: an input point and an output point. This is easier to understand. A function is essentially a mapping of the implementation process between input and output.
However, when the function implementation process is very long, do you choose to wait for the function to complete processing, or use a callback function for asynchronous processing? In this case, it becomes crucial to use callback functions, for example: AJAX requests. If you use a callback function for processing, the code can continue to perform other tasks without waiting in vain. In actual development, asynchronous calls are often used in JavaScript, and it is even highly recommended here!

The callback function is a function that is executed when something else ends. In Ajax, a callback function is a function called when the server responds to a request object. The browser will "call back" this function at some point.

The five states of callback?

Those onLoadSuccesses are generated by the plug-in based on the status of the underlying ajax
0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire response received.
3: (Interactive) the response is being parsed.
4 : (Completed) the response has been parsed, is ready for harvesting.

0 - (Uninitialized) The send() method has not been called
1 - (Loading) The send() method has been called, Sending the request
2 - (Loading completed) The send() method has been executed and all response content has been received
3 - (Interaction) The response content is being parsed
4 - (Complete) The response content parsing is completed , can be called on the client

The above is the detailed content of what is ajax callback. 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
Previous article:What is web front endNext article:What is web front end