Function that returns the value from updateData

what would be the proper way of coding this function:


retValue gets set in the callback from the model.updateData().  The problem seems to be that the function is returning before the callback is called, hence, returning zero.

Can we make the function wait until the callback is done before returning?  If so how would you do that?

Any thoughts?

Thank you.


  • edited May 8, 2019
    updataData() is asynchronous.  

    Here's a pattern that I use and you should be able to adopt it for your needs.
    var deferred = $.Deferred();
       .done(function () {
               // Success      
       .fail(function () {
               // Error
     }); ...
    return deferred.promise();

  • edited February 14, 2017
    Thanks for your input:

    I tried this and I still get the same issue.  You suggested to use $.Deferred() which is probably the piece I am missing.  I am not familiar with $.Deferred() so I am going to investigate.  Am I on the right track?

  • Rob HatchRob Hatch 💎💎💎
    edited September 1, 2016
    Do investigate the Deferred paradigm.  There are a number of community posts here where it is explained. 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!