gpt4 book ai didi

javascript - 如何等待Ajax成功:function to succeed to work next

转载 作者:行者123 更新时间:2023-12-03 02:46:32 27 4
gpt4 key购买 nike

无法确定 Ajax 成功的条件:

 function GetProm(){ 
var checkmoket = false;
$.ajax({
type: 'POST',
url: url,
data: { domain: b },
cache: false,
success: function (data)
{
var listProm = data.ListResult;
if (flagInside === 0)
for (var i = 0; i < listProm.length; i++)
{
if (listProm[i].ID === 384 || listProm[i].ID === 686)
{
checkmoket = true; // => here
}
}
}
});
if(checkmoket) // => checkmoket always is false
return;
}

为什么checkmoket总是错误的?如果条件正确,我希望 checkmoket 为 true?

最佳答案

尝试以下代码,我添加了async:false,您的函数签名错误是function GetProm{,我更正为function GetProm(){ :

function GetProm(){ 
var checkmoket = false;
$.ajax({
type: 'POST',
url: url,
data: { domain: b },
cache: false,
async:false, // New properties added.
success: function (data)
{
var listProm = data.ListResult;
if (flagInside === 0)
for (var i = 0; i < listProm.length; i++)
{
if (listProm[i].ID === 384 || listProm[i].ID === 686)
{
checkmoket = true; // => here
}
}
}
});
if(checkmoket) // => checkmoket always is false
return;
}

关于javascript - 如何等待Ajax成功:function to succeed to work next,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48071017/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com