JQuery ajax. If async is set to false, the synchronization operation fails. Solution: jqueryasync

Source: Internet
Author: User

JQuery ajax. If async is set to false, the synchronization operation fails. Solution: jqueryasync

Leading to failure:

 $.ajax({                url : 'your url',                data:{name:value},                cache : false,                 async : true,                type : "POST",                dataType : 'json/xml/html',                success : function (result){                    return result;                }            });

Solution:

 var ret = null;$.ajax({                url : 'your url',                data:{name:value},                cache : false,                 async : true,                type : "POST",                dataType : 'json/xml/html',                success : function (result){                    ret=result;                }            });return ret;


Note:

Do not return directly in the callback function of success. The specific cause will be investigated later !!


$ Ajax () Setting synchronous submission is invalid. The Code is as follows: async is set to "false", but it is still asynchronously submitted.

Ajax originally intended to perform asynchronous operations, and the latest jquery version even has discarded the async parameter.

If you only want to use ajax for server interaction and do not need to asynchronously refresh the effect, you can use a callback function.

The async: "false" in the jquery $ ajax function does not work.

"False" is a string when double quotation marks are added. A non-empty string is true.

Remove double quotation marks.

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.