I used Laravel Response :: json to generate a JSON response.
return Response::json(array('subjects' => $subjects, 'year' => $year, 'sem' => $sem));
When I run the request, I get valid JSON (verified in JSONLint) as the response.
But the following jQuery method does not work: $.parseJSON(data)
The following error appears in FireBug:
SyntaxError: JSON.parse: unexpected character in row 1 of column 2 of JSON data
The answer I get is:
{ "subjects": [ { "id": 1, "name": "Control Systems", "semester": 1, "year": 3, "branch_id": 4 }, { "id": 2, "name": "Analog Communications", "semester": 1, "year": 3, "branch_id": 4 }, { "id": 3, "name": "Linear IC Applications", "semester": 1, "year": 3, "branch_id": 4 }, { "id": 4, "name": "Antennas & Wave Propagation", "semester": 1, "year": 3, "branch_id": 4 } ], "year": 3, "sem": 2 }
And the code where I try to parse it:
$(document).ready(function() { $('#branchAndSubjects').click(function() { $.post('/findBranchAndSubjects', { roll: roll, _token: "{{csrf_token()}}" }, function(data) { var subjects = $.parseJSON(data); }); }); });
json jquery php
Faizuddin mohammed
source share