Hello, I make a get ajax request, and my controller is in charge of making query to the database and send the result into json format, I used the response()->json() like as mentioned in the [laravel documentation] (https://laravel.com/docs/5.1/responses#other-response-types) and I try to parse the result like that $.parseJSON(result);
but it throws an error (I check the JSON response and it's is valid). According to a stackoverflow user the result is not a JSON but an object [see here] (http://stackoverflow.com/questions/32635585/json-parse-error-on-a-seemingly-valid-json).
So I want to know why and how I can return a real json response.
Thank you a lot !!!!
For me, it's a result that could be parsed with the JSON.Parse() function without error no ?
It seems that if you have this:
var jsonObj = $.parseJSON(JSON.stringify(result));
You are converting it to a string just so you can convert it back. I'm not completely familiar with the nuances of '$.parseJSON' but I think you could just skip that conversion entirely:
var jsonObj = result;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community