Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
e1d081bd
Commit
e1d081bd
authored
Jan 05, 2013
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1501 from JesseObrien/master
Add Response::jsonp() to Response class.
parents
731cec24
4f5cc0cd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
home.md
laravel/documentation/views/home.md
+4
-0
response.php
laravel/response.php
+21
-1
No files found.
laravel/documentation/views/home.md
View file @
e1d081bd
...
...
@@ -62,6 +62,10 @@ Sometimes you will need a little more control over the response sent to the brow
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));
...
...
laravel/response.php
View file @
e1d081bd
...
...
@@ -98,6 +98,26 @@ class Response {
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.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment