From 16373e69048c8452002b191c4fd74aeb87270996 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 4 Feb 2021 10:22:10 +0100 Subject: [PATCH] Fix content-type on Ajax return --- src/includes/class/class.LSsession.php | 7 ++++++- src/includes/class/class.LStemplate.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/includes/class/class.LSsession.php b/src/includes/class/class.LSsession.php index 96306a65..163269ec 100644 --- a/src/includes/class/class.LSsession.php +++ b/src/includes/class/class.LSsession.php @@ -1703,8 +1703,13 @@ class LSsession { * @retval void */ public static function displayAjaxReturn($data=array(), $pretty=false) { + // Adjust content-type + header('Content-Type: application/json'); + + // If redirection set, just redirect user before handling messages/errors to + // keep it in session and show it on next page if (isset($data['LSredirect']) && (!LSdebugDefined()) ) { - echo json_encode($data); + echo json_encode($data, (($pretty||isset($_REQUEST['pretty']))?JSON_PRETTY_PRINT:0)); return; } diff --git a/src/includes/class/class.LStemplate.php b/src/includes/class/class.LStemplate.php index a8bbff60..d71058cb 100644 --- a/src/includes/class/class.LStemplate.php +++ b/src/includes/class/class.LStemplate.php @@ -457,6 +457,7 @@ class LStemplate extends LSlog_staticLoggerClass { public static function fatal_error($error=null) { http_response_code(500); if (LSsession :: get('api_mode')) { + header('Content-Type: application/json'); $errors = array(_("A fatal error occured. If problem persist, please contact support.")); if ($error) $errors[] = $error;