JQuery Ajax solve the problem of a sync operation failure when Async is False _jquery

Source: Internet
Author: User
Tags commit

jquery Ajax, when Async is false, the sync operation fails. Solutions, Jqueryasync

Recently do project encounter jquery Ajax, when Async is false, sync operation failure problem, the Internet search, get a solution, here on how to solve:

Code when a failure is thrown:

 $.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;

Description
Do not return directly in the success callback function, the specific reason behind in the investigation!!

$ajax () Set the synchronization commit is invalid, the code below, set async: "False" but still asynchronous commit

Ajax was intended for asynchronous operations, and the latest jquery version has even deprecated async parameters.

If you just want to use Ajax to do server interaction, do not need an asynchronous refresh effect, that can use the callback function.

jquery $ajax function, async in: "False" does not work to help look at

"false" adds double quotes as a string, and a non-empty string is true.

Remove the double quotes.

Thank you for reading, I hope to help you, thank you for your support for this site!

Related Article

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.