Skip to content

Commit

Permalink
Set X-Requested-With header for the AJAX request so anything using th…
Browse files Browse the repository at this point in the history
…e framework's 'isXmlHttpRequest' method on the request will work correctly
  • Loading branch information
mbabker committed Sep 7, 2022
1 parent 266ef87 commit d2e25df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Resources/assets/shop/js/add-to-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ export default class AddToCart {

form.classList.add('loading');

const response = await fetch(form.action, {method: form.method ?? 'POST', body: data});
const response = await fetch(form.action, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
method: form.method ?? 'POST',
body: data,
});

if (response.ok) {
validationElement.classList.add('hidden');
Expand Down
Loading

0 comments on commit d2e25df

Please sign in to comment.