diff --git a/laravel/documentation/views/home.md b/laravel/documentation/views/home.md index 53a0c4f3..3daf57a9 100644 --- a/laravel/documentation/views/home.md +++ b/laravel/documentation/views/home.md @@ -64,7 +64,7 @@ Sometimes you will need a little more control over the response sent to the brow #### Returning a JSONP response: - return Response::jsonp(array('name' => 'Batman')); + return Response::jsonp('myCallback', array('name' => 'Batman')); #### Returning Eloquent models as JSON: diff --git a/laravel/response.php b/laravel/response.php index 51ee33d6..5e69308f 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -103,7 +103,7 @@ class Response { * * * // Create a response instance with JSONP - * return Response::jsonp($data, 200, array('header' => 'value')); + * return Response::jsonp('myFunctionCall', $data, 200, array('header' => 'value')); * * * @param mixed $data @@ -111,11 +111,11 @@ class Response { * @param array $headers * @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'; - return new static(json_encode($data), $status, $headers); + return new static($callback.'('.json_encode($data).')', $status, $headers); } /**