Support the ongoing development of Laravel.io →
Requests Architecture Configuration

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 !!!!

Last updated 2 years ago.
0

What is a 'real json response'?

0

For me, it's a result that could be parsed with the JSON.Parse() function without error no ?

0

Thank you !

0

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;
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Khoya91170 khoya91170 Joined 10 Jun 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.