What setCallback is used for Laravel json response

I am going through a Laravel tutorial on how to create a simple API. But I don't understand what setCallback () is used for and how?

For example:

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'));
}

      

→ setCallback (Input :: get ('callback')); part

+3


source to share


2 answers


Used for JSONP response and is described in Special Replies If you want to know more about JSONP visit http://www.sitepoint.com/jsonp-examples/



+3


source


setCallback

not required. This is an optional feature to support JSONP requests in an API designed to be used by cross-domain JavaScript.



+1


source







All Articles