From 7a54476ff1ff8fc7185a7b64a49256b59ae6473d Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Thu, 24 Mar 2016 21:41:34 +0100 Subject: [PATCH] Always respond with JSON --- php/Modules/Response.php | 4 ++-- src/scripts/api.js | 11 +---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/php/Modules/Response.php b/php/Modules/Response.php index 289c42e..6ae5f30 100644 --- a/php/Modules/Response.php +++ b/php/Modules/Response.php @@ -6,13 +6,13 @@ final class Response { public static function warning($msg) { - exit('Warning: ' . $msg); + exit(json_encode('Warning: ' . $msg)); } public static function error($msg) { - exit('Error: ' . $msg); + exit(json_encode('Error: ' . $msg)); } diff --git a/src/scripts/api.js b/src/scripts/api.js index 83e800d..0cbfc15 100644 --- a/src/scripts/api.js +++ b/src/scripts/api.js @@ -26,15 +26,6 @@ api.post = function(fn, params, callback) { return false } - // Convert true and false to real booleans - if (data==='true') data = true - else if (data==='false') data = false - - // Convert to JSON if string start with '{' and ends with '}' - if (typeof data==='string' && data.substring(0, 1)==='{' && data.substring(data.length - 1, data.length)==='}') { - data = $.parseJSON(data) - } - callback(data) } @@ -49,7 +40,7 @@ api.post = function(fn, params, callback) { type: 'POST', url: api.path, data: params, - dataType: 'text', + dataType: 'json', success, error })