javascript - JSON syntax error in firefox only -
im getting syntax error in firefox when using $.parsejson(). same code works on chrome/chromium, , safari.
i call function random generated token set.
function gettoken() { var url = "/csrf_token_generate"; $.ajax({ url: url, method: "get" }).done(function(data) { console.log(data); // logs data call var json = $.parsejson(data); // error occurs token = json.token; console.log(token); }); } the url /csrf_token_genrate returns json object similar {"token":"$2y$10$jcr.p3fnqeji6rqd93lnxeiks9gynipj7cboahz8rccsgkw7vofhi"}
in url, setting content-type application/json works in every other browser.
the error im getting this
syntaxerror: json.parse: unexpected character @ line 1 column 2 of json data n.parsejson() jquery.min.js:4 gettoken/<() wheel.bak.js:94 n.callbacks/j() jquery.min.js:2 n.callbacks/k.firewith() jquery.min.js:2 x() jquery.min.js:4 .send/b/<() jquery.min.js:4 the object being console.log()'ed object { token: "$2y$10$60vxszivqushblvhsr5jpo6mqud4…" }
i can't seem track down why won't work in firefox, works fine in other browsers.
update 1
i figured out firefox trying parse parsed object, changed code along
function gettoken() { var url = "/csrf_token_generate"; $.ajax({ url: url, method: "get" }).done(function(data) { var json = data; token = json.token; console.log(token); }); } which works in firefox, not chromium.
so there than?
i think should check response headers -> content-type find actual data type. , compatible code should this.
# chrome if(typeof data === 'string') { } #for firefox if(typeof data === 'object') { }
Comments
Post a Comment