Fix content-type on Ajax return

This commit is contained in:
Benjamin Renard 2021-02-04 10:22:10 +01:00
parent 5c10277861
commit 16373e6904
2 changed files with 7 additions and 1 deletions

View file

@ -1703,8 +1703,13 @@ class LSsession {
* @retval void * @retval void
*/ */
public static function displayAjaxReturn($data=array(), $pretty=false) { 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()) ) { if (isset($data['LSredirect']) && (!LSdebugDefined()) ) {
echo json_encode($data); echo json_encode($data, (($pretty||isset($_REQUEST['pretty']))?JSON_PRETTY_PRINT:0));
return; return;
} }

View file

@ -457,6 +457,7 @@ class LStemplate extends LSlog_staticLoggerClass {
public static function fatal_error($error=null) { public static function fatal_error($error=null) {
http_response_code(500); http_response_code(500);
if (LSsession :: get('api_mode')) { if (LSsession :: get('api_mode')) {
header('Content-Type: application/json');
$errors = array(_("A fatal error occured. If problem persist, please contact support.")); $errors = array(_("A fatal error occured. If problem persist, please contact support."));
if ($error) if ($error)
$errors[] = $error; $errors[] = $error;