display_ajax_return(): add $pretty parameter

This commit is contained in:
Benjamin Renard 2021-07-28 17:15:46 +02:00
parent e936064b78
commit d76c21c526

View file

@ -146,8 +146,10 @@ function display_template($template, $pagetitle=false) {
} }
} }
function display_ajax_return($data) { function display_ajax_return($data=null, $pretty=false) {
global $debug_ajax; global $debug_ajax;
if (is_null($data))
$data = array();
if (isset($_SESSION['messages']) && !empty($_SESSION['messages'])) { if (isset($_SESSION['messages']) && !empty($_SESSION['messages'])) {
$data['messages'] = $_SESSION['messages']; $data['messages'] = $_SESSION['messages'];
unset($_SESSION['messages']); unset($_SESSION['messages']);
@ -159,7 +161,7 @@ function display_ajax_return($data) {
if ($debug_ajax) if ($debug_ajax)
logging('DEBUG',"Ajax Response : ".vardump($data)); logging('DEBUG',"Ajax Response : ".vardump($data));
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode($data); echo json_encode($data, (($pretty||isset($_REQUEST['pretty']))?JSON_PRETTY_PRINT:0));
exit(); exit();
} }