问题
I have such a control:
<asp:Button ID="save_all_filt" runat="server" Text="All data for filtered subjects"
OnClientClick=" a= saveAllFilt(); return true; " onclick="save_all_filt_Click" />
saveAllFilt contains a JQuery ajax call. So what I see in log, I have simultaneous start of postback and saveAllFilt. Postback however "delays" and does nothing before Ajax call in saveAllFilt fninshes.
I wonder if there is a way to do like this: 1. onClientClick, system goes into saveAllFilt JS function and somehow waits(!) till Ajax function finishes in this or that way. 2. Only when it is finished, a real postback starts to happen.
I do realise that JQuery ajax call is event-driven and asynchronous. Just would like to block these postback actions till it finishes (AJAX call prepares data for retrieval that happens via server postback.)
回答1:
Set the async property of the jQuery AJAX config object to false
:
$.ajax({
/* ... */
async : false
/* ... */
})
来源:https://stackoverflow.com/questions/13310883/asp-net-how-to-make-onclientclick-finish-work-before-postback