ajax
is the callback function in the inside 返回data再执行函数里面的代码
or is it 不等data返回就直接执行函数里面的代码
?
If this is the second case, how do you avoid the problem of asynchrony?
Reply content:
ajax
is the callback function in the inside 返回data再执行函数里面的代码
or is it 不等data返回就直接执行函数里面的代码
?
If this is the second case, how do you avoid the problem of asynchrony?
The callback function of the success is the function to be executed after data is successfully returned, that is, the data is not executed until it is obtained.
In other cases there are callbacks like Beforesend (before sending), complete (after the request is completed), error (Request error)
As for what you said about the problem of asynchrony I don't quite understand, can you give me an example?
Be sure to return data to execute the code inside the function = = do not return data to execute = = is not waiting for an error.
ajax
The full name of the AJAX = Asynchronous JavaScript and XML
(asynchronous JavaScript and XML).
First answer your question, success, the function will be executed when data is returned successfully. Do not return, will be very clever waiting for a while, this time is generally the network delay time. You can also set it yourself.
Below with a great jquery
frame of ajax
simple say.
Normally, I would use this in the form of Name+value.
$.ajax({name:value, name:value, ... })
async
A Boolean value that indicates whether the request is processed asynchronously. The default is true. set to False, you turn off asynchronous, at which point the interface will be very jammed.
beforeSend(xhr)
The function that is run before the request is sent.
The cache Boolean value that indicates whether the browser caches the requested page. The default is true.
complete(xhr,status)
A function that runs when the request completes (called after the request succeeds or fails, that is, after the success and the error function).
ContentType the type of content to use when sending data to the server. The default is: "Application/x-www-form-urlencoded".
The context specifies the "this" value for all AJAX-related callback functions.
data
Specifies the data to be sent to the server.
Datafilter (Data,type) functions for handling XMLHttpRequest raw response data.
dataType
The data type of the expected server response.
error(xhr,status,error)
The function to run if the request fails.
Global Boolean value that specifies whether to trigger an overall AJAX event handler for the request. The default is true.
Ifmodified Boolean value that specifies whether the request succeeds only if the response has changed since the last request. The default is False.
Jsonp A string that overrides the callback function in a JSONP.
JSONPCALLBACK Specifies the name of the callback function in a JSONP.
password Specifies the password that is used in HTTP access authentication requests.
ProcessData Boolean value that specifies whether the data sent through the request is converted to a query string. The default is true.
SCRIPTCHARSET specifies the requested character set.
success(result,status,xhr)
The function that is run when the request succeeds.
timeout
Sets the local request time-out (in milliseconds).
Traditional Boolean value that specifies whether to use the traditional style of parameter serialization.
type
Specifies the type of request (GET or POST).
url
Specifies the URL to send the request to. The default is the current page.
USERNAME Specifies the user name to use in HTTP access authentication requests. This can impersonate the user's login, plus password, you understand.
XHR the function used to create the XMLHttpRequest object.
The red part is my usual.
When the interface you requested is successfully responding to the data, callback the success function, so as long as your server is working properly, data will return what you want.
The answer to the question, which has already been said, I will not repeat, I just want to ask what you say the problem of async.