0

Basically I'm creating my own callback and passing it into my method called _ajaxCall().

_ajaxCall() takes the following parameters:

data = an object containing the user submitted data to be POSTed to my server postURL = the url to post to callback = a function expression to be called upon successful return of data from the server.

Here is the _ajaxCall() method:

_ajaxCall: function (data, postURL, callback) {
  $.post(postURL, {
    data : data
  }, 'json').done(function (returned) {
    switch(returned.success) {
      case true:
        typeof callback === 'function' && callback(returned);
        break;
    }
  }).fail(function (xhr, textStatus, errorThrown) {
    if (status !== 200) {
      window.location = document.URL;
    }
  });
}

commentUpdate : function(self) {
  var postURL = '/submission/comment/' + self.attributes.commentId;

  var data = {
    action: self.attributes.action,
    commentId : self.attributes.commentId,
    comment: self.attributes.comment
  };

  var callback = function(returned) {
    if (returned.success === true) {
      // do something in here
    } else {
      // do other crap here
    }
  };

  this._ajaxCall(data, postURL, callback);
}

But it's not passing returned to my custom callback() method. Why?

4

0 回答 0