Skip to content

Commit

Permalink
Use fail/then instead of error/done
Browse files Browse the repository at this point in the history
From the jQuery upgrade guide:

The jqXHR object returned from jQuery.ajax() is a jQuery Deferred and
has historically had three extra methods with names matching the
arguments object of success, error, and complete. This often confused
people who did not realize that the returned object should be treated
like a Deferred. As of jQuery 3.0 these methods have been removed.
As replacements, use the Deferred standard methods of done, fail,
and always, or use the new then and catch methods for Promises/A+
compliance.

Note that this does not have any impact at all on the ajax callbacks
of the same name passed through the options object, which continue to
exist and are not deprecated. This only affects the jqXHR methods.
  • Loading branch information
cpfergus1 committed Sep 13, 2022
1 parent 31187ce commit 87cde55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ Spree.Models.ImageUpload = Backbone.Model.extend({
}
return xhr;
}
}).done(function() {
}).then(function() {
that.set({progress: 100})
}).error(function(jqXHR, textStatus, errorThrown) {
}).fail(function() {
that.set({serverError: true});
});
}
Expand Down
22 changes: 9 additions & 13 deletions backend/app/assets/javascripts/spree/backend/shipments.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,26 @@ var ShipmentSplitItemView = Backbone.View.extend({
variant_id: this.variant.id,
quantity: quantity
};
var jqXHR;
var path;
if (target_type == 'stock_location') {
// transfer to a new location
split_attr.stock_location_id = target_id;
jqXHR = Spree.ajax({
type: "POST",
url: Spree.pathFor('api/shipments/transfer_to_location'),
data: split_attr
});
path = Spree.pathFor("api/shipments/transfer_to_location");
} else if (target_type == 'shipment') {
// transfer to an existing shipment
split_attr.target_shipment_number = target_id;
jqXHR = Spree.ajax({
type: "POST",
url: Spree.pathFor('api/shipments/transfer_to_shipment'),
data: split_attr
});
path = Spree.pathFor('api/shipments/transfer_to_shipment');
} else {
alert('Please select the split destination.');
return false;
}
jqXHR.error(function(msg) {
Spree.ajax({
type: "POST",
url: path,
data: split_attr
}).fail(function(msg) {
alert(Spree.t("split_failed"));
}).done(function(response) {
}).then(function(response) {
if (response.success) {
window.Spree.advanceOrder();
} else {
Expand Down

0 comments on commit 87cde55

Please sign in to comment.