From f1fe86a5921fd5c2eb3d7b7082e98b1e1d659b44 Mon Sep 17 00:00:00 2001 From: philibertperusse Date: Thu, 25 Apr 2013 19:10:48 -0300 Subject: [PATCH] Add application/json MIME type when returning JSON Added a call to PHP header('Content-type: application/json') so that Response header reflects the response JSON content --- src/EpiRoute.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/EpiRoute.php b/src/EpiRoute.php index 5a60cef..9c2ab19 100644 --- a/src/EpiRoute.php +++ b/src/EpiRoute.php @@ -139,7 +139,16 @@ public function run($route = false, $httpMethod = null) if (!is_null($response)) { $response = json_encode($response); - if(isset($_GET['callback'])) $response = "{$_GET['callback']}($response)"; + if(isset($_GET['callback'])) + { + $response = "{$_GET['callback']}($response)"; + } + else + { + // Set proper MIME type + header('Content-type: application/json'); + } + echo $response; } }