Quantcast
Channel: Opinion: Shopify Community - Shopify APIs & SDKs
Viewing all articles
Browse latest Browse all 25503

AJAX POST /cart/add.js Functions but returns Syntax Error by Paleo To Me

$
0
0

Hi, everyone!

I'm trying to figure out why I keep getting the following error as I'm trying to dynamically add items to a user's cart through the AJAX API:

parsererror SyntaxError: missing ; before statement

My JavaScript looks like this:

function processCart()
{  if (itemsToAdd.length > 0)  {    var request = itemsToAdd.shift();    var variantID= request.variantID;    var quantity = request.quantity;        console.log("Adding: " + variantID + " (x" + quantity + ") to cart.");        var cartAjaxUrl = "/cart/add.js";        //Make AJAX Call    jQuery.post(      cartAjaxUrl,       {        quantity: quantity,        id: variantID      }    )    .done(function(data) {      console.log("Success! Item added: " + data);            processCart();    })    .fail(function(jqxhr, textStatus, error) {      console.log("ERROR: " + textStatus + " " + error);            processCart();    });  }  else  {    //Redirect to cart    document.location.href = '/cart';  }
}

itemsToAdd is an array that contains both the variantID and quantity. I've verified their values in the console and the items are actually added to the cart, but the AJAX call always returns that above error.

Call me nitpicky, but that doesn't sit well with me and I'd like to know what it might be so I can fix it.

Does anyone have any ideas?

Thanks!

-Eric


Viewing all articles
Browse latest Browse all 25503

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>