"Unexpected Token :" Error Using JQuery With The Shopify Ajax Api

- 1 answer


When making a call to the shopify ajax api I am getting an error shown in the developer tools console.

Uncaught SyntaxError: Unexpected token :

Clicking on this error in the javascript console oddly shows the response which is valid JSON:

"title":"Ritual Petalos de rosas y vino tinto - Obispado",
"vendor":"Casa Azul Spa",
"product_title":"Ritual Petalos de rosas y vino tinto",
"product_description":"\u0026lt;!--\ntd {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}\n--\u003eRitual Pétalos de Rosas y Vino tinto, Exquisito masaje que ofrece bienestar, relajación e hidrata la piel. Realizamos el ritual con mascarilla hidratante y antioxidante, piedras calientes, y cuarzos para ofrecer un delicioso y aromático descanso a todo el cuerpo.",


The calling code is:

jQuery.getJSON('/products/'+getProduct.product_handle+'.js', function(product) {

    product.variants.forEach(function(variant) {
      if (getProduct.sucursal == variant.title){'/cart/add.js', {
          quantity: 1,



I'm working with Shopify with the template language Liquid, inside this liquid I have a <script> tag that runs AJAX for calling a method from Shopify.

More information

I know that the error it must have javascript syntax but like I said before I didn't see the error.

Anyone knows about this error?

I appreciate every answer.



Try using the long-form of the jquery.ajax call to specify all the AJAX parameters manually:

  type: 'post',
  dataType: 'json',
  data: { quantity:1, variant: }
  // Optional: success/error functions

Building on the other answers, it may be that jQuery is expecting one type of response header but is actually receiving a different type.

If this works, you should be able to go back to using by supplying a 4th parameter for the data type ('json'):