asp.net Knockoutjs Async call to JS library before submitting

38 views
Skip to first unread message

velli...@gmail.com

unread,
Oct 12, 2016, 1:52:02 PM10/12/16
to KnockoutJS

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         

};

velli...@gmail.com

unread,
Oct 13, 2016, 9:16:48 AM10/13/16
to KnockoutJS
Any one?

Doug S

unread,
Oct 14, 2016, 11:35:37 AM10/14/16
to KnockoutJS
This isn't so much a Knockout question as a JS question, but you'd basically need to do something like this:

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(); };
Reply all
Reply to author
Forward
0 new messages