gpt4 book ai didi

JavaScript 在继续之前等待 AJAX

转载 作者:行者123 更新时间:2023-12-02 23:12:23 24 4
gpt4 key购买 nike

在使用 kendo ui 进行内联网格编辑时单击更新时出现竞争条件。

保存时我在保存时执行以下函数:

dataBound: function (e) {
// This needs to run after the save has finished
},
save: function (e) {
$.when(
$.ajax({
type: "GET",
url: "/Admin/OperatingCentre/GetById?id=" + e.model.OperatingCentreId,
success: function (data) {
e.model.OperatingCentreName = data.Name;
}
}),
$.ajax({
type: "GET",
url: "/Admin/Division/GetById?id=" + e.model.DivisionId,
success: function (data) {
e.model.DivisionName = data.Name;
}
}),
$.ajax({
type: "GET",
url: "/Admin/OperatingCompany/GetById?id=" + e.model.OperatingCompanyId,
success: function (data) {
e.model.OperatingCompanyName = data.Name;
}
})
);
}

我所追求的是等待 $.when 函数,因为网格不会等到它调用数据绑定(bind),因此 e.model.OperatingCentreName 等没有及时设置以在网格中显示。

添加等待时这也没有帮助:

save: async function (e) {
await $.when(

如有任何建议,我们将不胜感激。

最佳答案

dataBound: function(e) {
// This needs to run after the save has finished
},
save: function(e) {
$.when(
$.ajax({
type: "GET",
url: "/Admin/OperatingCentre/GetById?id=" + e.model.OperatingCentreId,
success: function(data) {
e.model.OperatingCentreName = data.Name;
}
}),
$.ajax({
type: "GET",
url: "/Admin/Division/GetById?id=" + e.model.DivisionId,
success: function(data) {
e.model.DivisionName = data.Name;
}
}),
$.ajax({
type: "GET",
url: "/Admin/OperatingCompany/GetById?id=" + e.model.OperatingCompanyId,
success: function(data) {
e.model.OperatingCompanyName = data.Name;
}
})
).done(function(a1, a2, a3) {
// a1, a2, and a3 are arguments resolved for the each of the ajax requests, respectively.
// Each argument is an array with the following structure:
//[ data, statusText, jqXHR ]
// here trigger the dataBound
});
}

关于JavaScript 在继续之前等待 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57289528/

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