Getting 500 Internal Server Error using POST /cart/add.js

Hello There,

I'm getting 500 Internal Server Error when adding products using a Cart AJAX API(/cart/add.js).

Can anyone help me to fix this issue?

Below is the code which I'm using:

 

let $th_id_array = new Array(); 
$th_id_array.push({ id: 123, quantity: 1, }); 
const $th_bundle_formData = {items: $th_id_array}; 
fetch('/cart/add.js', { 
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify($th_bundle_formData) 
}).then(response => response.json()).then($th_addtocart_result => { 
  if($th_addtocart_result.items.length > 0){ 
    console.error($th_addtocart_result); 
  } 
}).catch(($th_addtocart_error) => {
  console.error($th_addtocart_error); 
});

 

0 Likes
Matt-Pipelabs
Excursionist
13 1 1

Hey @WebContrive ,

If you open up the Developer Tools in your browser, open the Network tab and click into the request that is failing you should be able to see the reason why.

0 Likes

Hello @Matt-Pipelabs,

Thank you so much for your quick response.

I have checked the Network tab and it is also showing the same error (500 Internal Server Error).

0 Likes