AJAX add to cart Unexpected token ':'

Highlighted
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
Highlighted
Shopify Partner
360 28 47

@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 Expert | Skype: akshayvaghasiya84
 - Like and Mark as an Accepted Solution if my reply helpful
 - Feel free to contact me on akshayvaghasiya84@gmail.com for any queries
 - Want to modify or custom changes on store hire me .
0 Likes
Highlighted
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
Highlighted
Shopify Partner
360 28 47

@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 Expert | Skype: akshayvaghasiya84
 - Like and Mark as an Accepted Solution if my reply helpful
 - Feel free to contact me on akshayvaghasiya84@gmail.com for any queries
 - Want to modify or custom changes on store hire me .
0 Likes
Highlighted
Excursionist
14 1 1

you need to set data type to json

1 Like