Hello. There were problems with the transfer of the code http://salejs.com/ I am trying to transfer it from someone else's server to my own, I installed everything, it looks like it works, but it gives this error when sending the form from the site (I assume that when processing it, the message about successful sending out, but the letter does not come):

Uncaught SyntaxError: Unexpected token v in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.xhr.onreadystatechange (cart.js:64) xhr.onreadystatechange @ cart.js:64 

File cart.js Listed lines

 xhr.onreadystatechange = function(){ if(responded) return if(xhr.readyState == 4){ responded = true if(xhr.status == 200) callback(null, JSON.parse(xhr.responseText)) else callback(new Error(xhr.responseText)) } } 

Consoles do not like this line

 if(xhr.status == 200) callback(null, JSON.parse(xhr.responseText)) 

I tried to look for a solution to the problem on my own, but it did not work out. If it is not difficult, tell me the solution, or at least indicate the direction in which to look. Thank.

Closed due to the fact that off-topic participants Dmitriy Simushev , user194374, vp_arth , Denis Bubnov , Sasha Omelchenko 2 Mar '17 at 10:03 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Dmitriy Simushev, Community Spirit, vp_arth, Denis Bubnov, Sasha Omelchenko
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What comes in response from the server? - Dmitriy Simushev
  • file cart.js HTTP response messages HTTP / 1.1 304 Not Modified Date: Sat, 25 Feb 2017 17:33:17 GMT Server: Apache / 2.4.6 (CentOS) PHP / 5.6.30 Connection: Keep-Alive = 5, max = 100 Etag: "753e-5495da3674266" - Alex Sibrin
  • one
    And the body? Vanguyu, there is invalid JSON - hence the error. - Dmitriy Simushev
  • In the response body (firebug and chrome debuger) shows the cart.js code: test.studionova.tech/client/cart.js - Alex Sibrin

1 answer 1

You have an error message: "Uncaught SyntaxError: Unexpected token in JSON at position 0" while executing JSON.parse. This message means that the very first character of the JSON.parse argument was the letter v, which should not be. Try in the browser console to execute

 JSON.parse('v'); 

and you will see the same error message.

The value of the JSON format is either an object (then the first character must be {- the left curly bracket), or an array (then the first character must be [- the left square bracket).

  • one
    Usually null is also valid JSON;) - Dmitriy Simushev
  • Thank! app.post is not properly registered. Thanks again. - Alex Sibrin