The return statement in jquery Ajax cannot return a value

Source: Internet
Author: User

Today, when making a new requirement, use jquery's Ajax to return a query result:

But when this method is called, the data has the information, the call of the place obtained is always undefined, in the online search for some information, found the problem, the solution is as follows:

1: The attribute needs to increase async:false;

2: Declare a variable before Ajax, in success, assign data to the variable, and after Ajax, return the variable;

Because if it is asynchronous execution, perhaps the query results have not returned, JS this way to return the data back, but only add the Async:false attribute but does not solve the problem;

Return to data directly, it will still be undefined, why this place to use a variable to accept the data, and then return the variable, I do not know why;

First of all hope that this place can help everyone, but also hope that the 2nd more understanding of the friends can answer my questions;

The return statement in jquery Ajax cannot return a value

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.