Merge pull request #1501 from JesseObrien/master
Add Response::jsonp() to Response class.
This commit is contained in:
commit
e1d081bd54
|
@ -62,6 +62,10 @@ #### Returning a JSON response:
|
|||
|
||||
return Response::json(array('name' => 'Batman'));
|
||||
|
||||
#### Returning a JSONP response:
|
||||
|
||||
return Response::jsonp('myCallback', array('name' => 'Batman'));
|
||||
|
||||
#### Returning Eloquent models as JSON:
|
||||
|
||||
return Response::eloquent(User::find(1));
|
||||
|
|
|
@ -98,6 +98,26 @@ public static function json($data, $status = 200, $headers = array())
|
|||
return new static(json_encode($data), $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new JSONP response.
|
||||
*
|
||||
* <code>
|
||||
* // Create a response instance with JSONP
|
||||
* return Response::jsonp('myFunctionCall', $data, 200, array('header' => 'value'));
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @return Response
|
||||
*/
|
||||
public static function jsonp($callback, $data, $status = 200, $headers = array())
|
||||
{
|
||||
$headers['Content-Type'] = 'application/javascript; charset=utf-8';
|
||||
|
||||
return new static($callback.'('.json_encode($data).');', $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new response of JSON'd Eloquent models.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue