I’m having some trouble getting JSON to store some Javascript as a string value.
{
"code": "function test(){alert('coreg.js has been loaded'); if (jQuery) { alert('We have jQuery!'); } else { alert('We don\'t have jQuery...'); } }"
}
When I validate this using http://www.jsonlint.com it says I’ve got a syntax error (unexpected TINVALID at line 2) but I can’t for the life of me see what it is. The Javascript is all entirely valid, all I did was take my function and put double quotes outside it.
I’m really confused! Does anyone know what I’m doing wrong?
you need to escape the escape:
We don\\'t have jQuerythough if you are using json to get JS code from another domain, you wont be able to do it unless the other domain supports JSONP, or you are using grease monkey’s XHR