Problems storing json sent from laravel controller into a javascript variable in the View.
The controller code
public function list() {
$rst=\App\Emp::all();
$json_rsp=response()->json($rst);
return view('emp')->with('json',$json);
}
In my View I am trying to store the response in a JavaScript variable
var data={{ $json }};
View-> Source the variable contains
HTTP/1.0 200 OK
Cache-Control: no-cache, private
Content-Type: application/json
Date: Fri, 11 Jan 2019 06:10:50 GMT
{"id":1,"e_name":"Kate","type":"Mixed","dof":"2004-12-12" ETC ETC
Parsing this data using JSON.parse throws an error.
I expect to store pure json in javascript variable to put it to further use but as the response has headers the input is not proper JSON. Is there any way to send JSON data from Controller to the view without the headers? I am using Laravel 5.7 by the way.