0

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);
});
Ben
  • 11
  • 1
  • TL;DR `fetch("/cart/change.js", { method: "POST", body: new URLSearchParams(changes) }).then(r => r.json()).then(ajaxify.onCartUpdated)` – Phil Feb 10 '22 at 04:13

0 Answers0