dangerChihuahua007
dangerChihuahua007

Reputation: 20895

Why am I getting a JSON parsing error from a jQuery Ajax operation?

I am using jQuery Ajax to return a JSON object (with dataType: 'json') from a PHP file. Here is the returned JSON string that the PHP file echoes out.

{'works': true,'text':'<div class=\'animal\'>Elephant</div><br />'}

The Chrome web developer console notes Error:parsererror SyntaxError: Unexpected token '. I do not see, however, where an unexpected single quote could be.

Upvotes: 1

Views: 2191

Answers (2)

Jones
Jones

Reputation: 1500

This question is similar of your problem. The echo is correct. See extra content return to client Creating JSON data using PHP and parsing it using jQuery

Upvotes: 1

JayC
JayC

Reputation: 7141

Your JSON is invalid

Use double quotes. Double quotes!

Upvotes: 3

Related Questions