ajax json同步无法与设置为false的async一起工作

ajax json synchronous not working with async set to false

本文关键字:false async 一起 工作 设置 同步 json ajax      更新时间:2023-09-26

同步ajax不工作:

        var rslt = false;
            $.ajax({
                async: false,
                url: url,
                dataType: "json",
                success: function(data) {                      
                     rslt = true;                      
                }                      
                });

            document.write(rslt);

rslt仍然显示为false。

我没主意了。。。

您可以通知它是GET还是POST,因为您没有传递任何信息,我认为它是GET,所以将类型设置为"GET"

这应该有效:

var rslt = false;
            $.ajax({
                async: false,
                type: 'GET',
                dataType: 'json',
                url: url,
                success: function(data) {                      
                     rslt = true;                      
                }                      
            });

document.write(rslt);