I am using Knockoutjs in old asp.net webapplication. I have requirement that on asp.net submit button click, I must call as JS library async and get response and then post the asp.net submit (i.e initiate asp.net button click event)?
Is there a way in Knockoutjs to wait for response from Async call and then submit? problem I have is since asp.net is sync and I when I make async call to JS library the form is submitting even before I receive response from JS library.
self.onButtonClick = function () {
var jsdatatosubmit = {
param1: '123',
param2: '123qwewe'
};
object.functionTest(jsdatatosubmit)
.success(
function (response) {
return true; //Submit asp.net form Call submit click event
}
)
.error();
return false; //instead of true
};
self.onButtonClick = function (data, event) {
//block the submit
event.preventDefault();
var jsdatatosubmit = {
param1: '123',
param2: '123qwewe'
};
object.functionTest(jsdatatosubmit)
.success(
function (response) {
//submit the form when the callback completes
//assuming there's a single form since it's asp.net
document.forms[0].submit();
}
)
.error();
};