Answer the question
In order to leave comments, you need to log in
How to load parameters in JS on first page load?
It is necessary to transfer JSON with various parameters during the first load, how can this be done?
I use Laravel - when I pass a json_encode object, then it can’t properly assign it (for some reason, all characters are immediately escaped).
(AJAX request immediately after loading exclude)
foreach($allImages as $image){
$arr[] = $image->__toString();
}
$json_arr = json_encode($arr);
return view('index', ['images' => $arr, 'json_images' => $json_arr]);
Answer the question
In order to leave comments, you need to log in
You can put js-code in the view that assigns variables to window, and read them from there in javascript. There is such package for Laravel: https://github.com/laracasts/PHP-Vars-To-Js-Transformer
Are you parsing the incoming JSON https://developer.mozilla.org/en/docs/Web/JavaScri...
What does the escaped string look like?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question