gpt4 book ai didi

javascript - ASP.NET:如何仅在客户端 ajax 完成后才提交回发

转载 作者:行者123 更新时间:2023-11-30 08:52:09 24 4
gpt4 key购买 nike

我有一个这样编码的按钮:

<asp:Button ID="save_all_filt" runat="server" Text="All data for filtered subjects"
ClientIDMode="Static" OnClientClick="a= saveAllFilt(); return a; "
OnClick="save_all_filt_Click" />

saveAllFilt 是调用通常的 JQuery ajax 调用的函数。像这样:

  function saveAllFilt() {
jQuery.ajax({
async: false,
dataType: 'json',
contentType: "application/json; charset=utf-8",
type: "POST",
url: contentURL,
data: dataarray,
success: function (msg) {
// Some processing here. ONLY WHEN IT IS DONE, I NEED TO HAVE POSTBACK.
},
error: function (data) {

}
}); // end of ajax call.

我想要这样的东西:只有在 ajax 调用完成后,onClick 才会继续。我该怎么做?

最佳答案

您可以从按钮中删除 OnClick 属性并在 OnClientClick 属性中返回 false,例如:

<asp:Button ID="save_all_filt" runat="server" Text="All data for filtered subjects"
ClientIDMode="Static" OnClientClick="saveAllFilt(); return false;" />

并使用 OnClick 属性设置隐藏按钮,例如:

<asp:Button ID="hdnButton" runat="server" Text="" Visible="False" 
ClientIDMode="Static" OnClick="save_all_filt_Click" />

然后在您的 ajax 调用的成功方法中单击该按钮,例如:

success: function (msg) {
// Some processing here. ONLY WHEN IT IS DONE, I NEED TO HAVE POSTBACK.
$('#hdnButton').click();
},

关于javascript - ASP.NET:如何仅在客户端 ajax 完成后才提交回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16916884/

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