Added callback wrapper for JSONP auto wrapping.
This commit is contained in:
parent
cf6e2a768b
commit
404b59730a
|
@ -64,7 +64,7 @@ #### Returning a JSON response:
|
||||||
|
|
||||||
#### Returning a JSONP response:
|
#### Returning a JSONP response:
|
||||||
|
|
||||||
return Response::jsonp(array('name' => 'Batman'));
|
return Response::jsonp('myCallback', array('name' => 'Batman'));
|
||||||
|
|
||||||
#### Returning Eloquent models as JSON:
|
#### Returning Eloquent models as JSON:
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ public static function json($data, $status = 200, $headers = array())
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* // Create a response instance with JSONP
|
* // Create a response instance with JSONP
|
||||||
* return Response::jsonp($data, 200, array('header' => 'value'));
|
* return Response::jsonp('myFunctionCall', $data, 200, array('header' => 'value'));
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
|
@ -111,11 +111,11 @@ public static function json($data, $status = 200, $headers = array())
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public static function jsonp($data, $status = 200, $headers = array())
|
public static function jsonp($callback, $data, $status = 200, $headers = array())
|
||||||
{
|
{
|
||||||
$headers['Content-Type'] = 'application/javascript; charset=utf-8';
|
$headers['Content-Type'] = 'application/javascript; charset=utf-8';
|
||||||
|
|
||||||
return new static(json_encode($data), $status, $headers);
|
return new static($callback.'('.json_encode($data).')', $status, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue