0

In the below function as you can see in the .save() part there is no response object, I would like to know how do i declare a response object to get a return value.

        $.when(
            _this.formWebsitePart.save({
                success: function () {
                    console.log("website saved")
                    _this.formWebsitePart.isSaved = true;
                }
            }),
            _this.formAddressPart.save({
                success: function () {
                    console.log("address saved")
                }
            })
        ).then(function () {
                _this.signupSuccess();
            }
        )
Cœur
  • 37,241
  • 25
  • 195
  • 267
Rahul92
  • 1
  • 4

1 Answers1

0

If your .save() genuinely returns a jqXHR object, then you probably want something like this :

_this.saveFormParts = function() {
    if(!_this.formWebsitePart.jqXHR) {
        _this.formWebsitePart.jqXHR = _this.formWebsitePart.save().then(function(response) {
            console.log("website saved");
            return response || null;
        });
    }
    if(!_this.formAddressPart.jqXHR) {
        _this.formAddressPart.jqXHR = _this.formAddressPart.save().then(function(response) {
            console.log("address saved");
            return response || null;
        });
    }
    return $.when(
        _this.formWebsitePart.jqXHR,
        _this.formAddressPart.jqXHR
    );
}

And, wherever appropriate :

_this.saveFormParts().then(_this.signupSuccess); // or similar

If your .save() doesn't return a jqXHR object, then you will need to do one of the following :

  • write a promisified version of .save() (preferred)
  • write a promisified version of .saveFormParts()

For promisification of a conventional callback interface - try this

Community
  • 1
  • 1
Roamer-1888
  • 19,138
  • 5
  • 33
  • 44