AJAX add to cart Unexpected token ':'

Shopify Partner
5 0 2

I am trying to follow the shopify docs to create a simple add to cart button for a product.

 

My code is below:

 

 

$(".addItem").on("click", function() {
  
jQuery.post('/cart/add.js', {
  quantity: 1,
  id: 28799832031312   
});
   
});

When I click the button it throws an error:

 

Uncaught SyntaxError: Unexpected token ':'

 

And then the item appears in the cart after refresh of the page.

 

 

0 Likes
Shopify Partner
90 8 10

@MarkChief 

Because you are doing the wrong code there. Please share your store URL and link where you want to use this code.

Thanks & Regards
Akshay Vaghasiya

Shopify Partner | Shopify Experts
Email: akshayvaghasiya84@gmail.com
Skype: akshayvaghasiya84
 - Want to modify or custom changes on store hire me .
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
0 Likes
Shopify Partner
5 0 2
Thanks. I do not have a public url at the moment. But I am trying to use this in a product page in the product-grid file.

Please can you tell me how it is wrong so I can look to fix it? Thanks.
0 Likes
Shopify Partner
90 8 10

@MarkChief 

If URL is not public then you need to give me ADMIN access as a collaborator account. Because this issue is regarding ajax functionality for that I need to check your liquid code as well as Ajax code. 

Thanks & Regards
Akshay Vaghasiya

Shopify Partner | Shopify Experts
Email: akshayvaghasiya84@gmail.com
Skype: akshayvaghasiya84
 - Want to modify or custom changes on store hire me .
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
0 Likes