I am in the process of replacing ajax with fetch but have run into a problme when trying to execute a method.
Here is the orginal post request.
$.post('/cart/change.js', changes, ajaxify.onCartUpdated, 'json');
And here is the updated code. I dont get an error, but the method is not called.
let
quantity = this.value,
id = $(this).attr('id').replace('updates_', ''),
changes = {
quantity: quantity,
id: id
},
fetch('/cart/change.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(changes)
})
.then(response => {
return response.json();
})
.then(function() {
return ajaxify.onCartUpdated;
})
.catch((error) => {
console.error('Error:', error);
});