Last active
November 5, 2015 09:28
-
-
Save srugano/4b81048408aef73a5f80 to your computer and use it in GitHub Desktop.
when jQuery.parseJSON() throws an invalid json excepion for a Json retrieved from a django backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get the json object in the django template : | |
var data = "{{object|safe}}"; | |
// Parse the JSON data | |
try | |
{ | |
// Use jquery's default parser | |
data = $.parseJSON(data); | |
} | |
catch(e) | |
{ | |
/* | |
* Fix a bug where strange unicode chars in the json data makes the jQuery | |
* parseJSON() throw an error (only on some servers), by using the old eval() - slower though! | |
*/ | |
data = eval( "(" + data + ")" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment