summaryrefslogtreecommitdiffstats
path: root/web/lib/aurjson.class.php
diff options
context:
space:
mode:
authorelij <elij.mx@gmail.com>2009-09-27 16:43:38 -0700
committerLoui Chang <louipc.ist@gmail.com>2009-09-28 15:17:07 -0400
commita6d5cb71a69b0296222a0a43fa18279e98686d12 (patch)
tree72b3a567d97d68b0784d2d6c53545aec386c5633 /web/lib/aurjson.class.php
parent94b1e165e12ff12e2caf01913fdec52009215210 (diff)
downloadaurweb-a6d5cb71a69b0296222a0a43fa18279e98686d12.tar.xz
fix content-type when sending jsonp
jsonp callback should have a content type of text/javascipt, since it specifies a callback function wrapping json data, and is not soley json data. Signed-off-by: Loui Chang <louipc.ist@gmail.com>
Diffstat (limited to 'web/lib/aurjson.class.php')
-rw-r--r--web/lib/aurjson.class.php12
1 files changed, 8 insertions, 4 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index befb639..06247eb 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -11,7 +11,7 @@ if (!extension_loaded('json')) {
include_once("aur.inc");
/**
- * This class defines a remote interface for fetching data
+ * This class defines a remote interface for fetching data
* from the AUR using JSON formatted elements.
* @package rpc
* @subpackage classes
@@ -28,9 +28,6 @@ class AurJSON {
* @return string The JSON formatted response data.
**/
public function handle($http_data) {
- // set content type header to json
- header('content-type: application/json');
-
// handle error states
if ( !isset($http_data['type']) || !isset($http_data['arg']) ) {
return $this->json_error('No request type/data specified.');
@@ -47,9 +44,14 @@ class AurJSON {
// allow rpc callback for XDomainAjax
if ( isset($http_data['callback']) ) {
+ // it is more correct to send text/javascript
+ // content-type for jsonp-callback
+ header('content-type: text/javascript');
return $http_data['callback'] . "({$json})";
}
else {
+ // set content type header to app/json
+ header('content-type: application/json');
return $json;
}
}
@@ -65,6 +67,8 @@ class AurJSON {
* @return mixed A json formatted error response.
**/
private function json_error($msg){
+ // set content type header to app/json
+ header('content-type: application/json');
return $this->json_results('error',$msg);
}