I am writing “comments” from my website in my database with PHP using mysql_real_escape_string(). this will escape stuff out, as well as single-quote (‘) and double-quotes (“). when I load these comments back into my website, I’m using AJAX to load them, triggered by the scroll bar of a DIV to load 5 more on each scroll bar that reached bottom of DIV.
Everything works fine until an entry containes escaped \’ (single-quote)
var ajax_entry_items = JSON.parse(http.responseText);
the JSON.parse function gives the error
Uncaught SyntaxError: Unexpected token ‘ in Google Chrome.
How can I still input single-quotes and double-quotes in my comments in my database and bring them back to display them on the website ? The double-quotes and single-quotes come back escaped but for some reason the single-quote, escaped, generates the
Unexpected token” error.
Thanks.
It is not allowed to enclose strings in single quotes, nor to escape single quotes, in JSON. You must escape double quotes and must not escape single quotes.