Home > Web Front-end > JS Tutorial > body text

jQuery ajax solves the problem of synchronization failure when async is false

高洛峰
Release: 2016-12-06 14:51:19
Original
1102 people have browsed it

jQuery’s ajax, when async is false, the synchronization operation fails. Solution, jQueryasync

recently encountered jquery's Ajax of Jquery. When Async is False, the problem of failed to operate synchronously, search online, and get the solution.

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

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;
Copy after login

Instructions:

Don’t return directly in the success callback function, the specific reasons will be investigated later! !

$ajax() is invalid for setting synchronous submission. The code is as follows. Async: "false" is set but it is still submitted asynchronously.

The original purpose of ajax is to perform asynchronous operations, and the latest jQuery version has even deprecated the async parameter. .

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

jquery $ajax function, async: "false", if it doesn't work, please help

"false" is a string if double quotes are added, and a non-empty string is true.

Remove the double quotes.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template