Answer the question
In order to leave comments, you need to log in
Uncaught SyntaxError: Unexpected token on parseJSON(). How to fix?
Write data from php (Laravel) to js variable.
var objects = "{{json_encode($objects)}}";
objects = objects.replace(/"/g,'"');
console.log(jQuery.parseJSON(objects));
VM3905:1 Uncaught SyntaxError: Unexpected token
Answer the question
In order to leave comments, you need to log in
There is no need to escape data when outputting, and everything will work without crutches with replace.
And if you do not wrap it in quotes, then you won’t need to parse it later - after all, json_encode immediately returns valid js.var objects = {!! json_encode($objects) !!};
"{{json_encode($objects)}}" - this definitely doesn't match the json format
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question