gpt4 book ai didi

javascript - Jquery Ajax 调用,不调用成功或错误

转载 作者:IT王子 更新时间:2023-10-29 03:23:05 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How do I return the response from an asynchronous call?

我正在使用 Jquery Ajax 调用服务来更新值。

function ChangePurpose(Vid, PurId) {
var Success = false;
$.ajax({
type: "POST",
url: "CHService.asmx/SavePurpose",
dataType: "text",
data: JSON.stringify({ Vid: Vid, PurpId: PurId }),
contentType: "application/json; charset=utf-8",
success: function (data) {
Success = true;//doesn't go here
},
error: function (textStatus, errorThrown) {
Success = false;//doesn't go here
}

});
//done after here
return Success;
}

和服务:

[WebMethod]
public string SavePurpose(int Vid, int PurpId)
{
try
{
CHData.UpdatePurpose(Vid, PurpId);
//List<IDName> abc = new List<IDName>();
//abc.Add(new IDName { Name=1, value="Success" });
return "Success";
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

正在从 AJAX 成功调用该服务。 值(value)也正在改变。但在服务之后,成功:错误:函数未被调用,在这种情况下,应该调用成功,但它不起作用。

我使用 firebug 发现,成功或错误函数被跳过并直接进入 return Success;

似乎找不到代码的问题。

更新:添加 async: false 解决了问题

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