I’m using an AJAX request. This is the first time I’m using JSON or any of it’s methods. The ajax utility returns an argument to the onreadystatechange callback as the responseText or responseXML of the file I’m requesting. Using a simple info.txt and request.responseText will work fine but when I try info.js and JSON.parse it returns “Unexpected token ILLEGAL” when I’ve checked multiple times that my syntax is correct. Here is the JSON:
JSON:
{
first: 1,
second: 2
}
JSON.parse()is very strict in grammar. The key/value pairs should have the form:So the “first” and “second” should be string in a JSON object.
Change your JSON to following code and it should be right