Recently, in the laravel framework, the json string passed in the background was obtained from the front-end Blade template, and the " character was found. The phenomenon is as follows:
/*后端*/
$x_char = ["2017-10-25","2017-10-24"];
return view(xxx, ['x_char' => json_encode(x_char)]);
/*前端*/
<script>
var x_char = "{{ $x_char }}";
console.log( x_char ); //输出 ["2017-10-25","2017-10-24"]
</script>
Obviously, the json data passed to the Balde template by the backend interface is escaped. And I don't need the escaped json string.
There are blog posts on the Internet, and these escape characters are converted back with js regularity, but it is troublesome.
Later, I saw this post, and when I sent the Blade template to receive variables, use {!! $x !!} to prevent $x from being escaped by the php function htmlspecialchars.
Original post: https://segmentfault.com/q/1010000010580668
Laravel official website introduction: https://laravel.com/docs/5.4/blade#displaying-data
The modification code is as follows:
/*前端*/
<script>
var x_char = {!! $x_char !!};//将 "{{ $x_char }}" 改为 {!! $x_char !!} 即可
console.log( x_char ); //输出 ["2017-10-25", "2017-10-24"]
</script>