Javascript-ajax Async Problem

Source: Internet
Author: User

ajaxis 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:

ajaxis 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.

ajaxThe 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, ... })
  • asyncA 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.

  • dataSpecifies the data to be sent to the server.

  • Datafilter (Data,type) functions for handling XMLHttpRequest raw response data.

  • dataTypeThe 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.

  • timeoutSets the local request time-out (in milliseconds).

  • Traditional Boolean value that specifies whether to use the traditional style of parameter serialization.

  • typeSpecifies the type of request (GET or POST).

  • urlSpecifies 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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.