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);
});