Skip to content Skip to sidebar Skip to footer

Can't Solve Code In Ajax,php,json,laravel(php Framework)

Can't access the json encoded data sent from a php function(Using laravel framework) to an ajax call. I am encoding the database results This is the php function I am using pu

Solution 1:

The problem is that the content-type on the response is text/html. This makes jquery think the response is html. jquery does not parse the json in that case. To solve this problem simply remove the json_encode. Your laravel controller should look like this:

$first_name = Input::get('firstname');
$last_name = Input::get('lastname');
$student_id = Input::get('student_id');

if(!empty($first_name) && empty($last_name) && empty($student_id)) {
    return Learners::where('first_name','=',$first_name)->get();
}

This works because when you return a collection, Laravel will automatically convert it to json and set the content-type to application/json.

Also note that you should use the Input facade to get the post variables rather than using the _POST superglobal.

Post a Comment for "Can't Solve Code In Ajax,php,json,laravel(php Framework)"