How to use the standard fetch and post method in SCA

The fetch method in SCA. We can pass the values inside the fetch function.The example is added below

 this.model = options.model;
            this.recordsPerPage = 10;
            var urlOptions = Utils.parseUrlOptions(location.href) || { page: 1 };
            urlOptions.page = urlOptions.page || 1;
            this.result = [];
            var self = this;
            this.model.fetch({ data: { page: urlOptions.page, recordsPerPage: this.recordsPerPage } }).done(function(result) {
                self.result = self.model.get('records');
                if (self.result.length) {
                    self.setTable(self.result);
                }
                self.render();
            });

The standard post method of form submission example is added below

var promise = BackboneFormView.saveForm.apply(this, arguments);
            var self = this;
            promise && promise.done(function promiseThen(response) {
                if (response.success) {
                    var line = LiveOrderLineModel.createFromProduct(self.options.item);
                    var quantity = line.get('quantity');
                    if (!quantity) {
                        line.set('quantity', 1)
                    }
                    self.addToSaveForLater(line).done(function addToSaveForLater() {
                        self.showConfirmationMessage(_('The item is added to your back in stock subscription.').translate(), true)
                    })
                } else {
                    self.showError('You\'ve already signed up to be notified')
                }
            });
            promise && promise.fail(function failPromise(response) {
                self.showError(response && response.responseJSON && response.responseJSON.errorMessage || 'An Error has ocurred.')
            })

Leave a comment

Your email address will not be published. Required fields are marked *