Skip to content

Commit 3eed558

Browse files
zosterPhil Sturgeon
authored andcommitted
Added JSONP support for client side AJAX requests. Many APIs (Vimeo and Google come to mind) support this type of access, and we wanted to support it for our service as well. It basically wraps the JSON with a callback function as defined by the client.
GitHub user SomethingOn implemented this on our REST API, and we thought others might benefit from it as well.
1 parent 44364e3 commit 3eed558

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

application/libraries/REST_Controller.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class REST_Controller extends Controller
2222
'xml' => 'application/xml',
2323
'rawxml' => 'application/xml',
2424
'json' => 'application/json',
25+
'jsonp' => 'application/json',
2526
'serialize' => 'application/vnd.php.serialized',
2627
'php' => 'text/plain',
2728
'html' => 'text/html',
@@ -811,6 +812,12 @@ private function _format_json($data = array())
811812
{
812813
return json_encode($data);
813814
}
815+
816+
// Encode as JSONP
817+
private function _format_jsonp($data = array())
818+
{
819+
return $this->get('callback').'('.json_encode($data).')';
820+
}
814821

815822
// Encode as Serialized array
816823
private function _format_serialize($data = array())

0 commit comments

Comments
 (0)