Sunday, February 13, 2022

[FIXED] What setCallback is used for in Laravel json response

Issue

I am going through a Laravel tutorial on how to build a simple API. But I dont understand what the setCallback() is used for and how?

Eg:

public function index()
{
    $data = Input::get('data');

    If ( $data == ''){
        // query DB get all results
    }else{
        // query DB and get specific result
    }
    return Response::json(array(
            'error' => false,
            'stores' => $data->toArray()),
        200
    )->setCallback(Input::get('callback'));
}

The ->setCallback(Input::get('callback')); part


Solution

Is used for JSONP response and it's described in Special Responses If you want to know more about JSONP visit http://www.sitepoint.com/jsonp-examples/



Answered By - user3657823

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.