instead of sending nothing, which gives a parse error on client-side, send a valid, empty response

This commit is contained in:
Ralf Becker 2013-08-01 12:28:28 +00:00
parent 596a01a76d
commit 207b7de248

View File

@ -240,8 +240,6 @@ class egw_json_response
call_user_func_array($proc['proc'], $proc['params']);
}
//$inst->sendHeader();
// check if application made some direct output
if (($output = ob_get_clean()))
{
@ -256,11 +254,8 @@ class egw_json_response
}
}
if($inst->haveJSONResponse())
{
echo $inst->getJSON();
$inst->initResponseArray();
}
echo $inst->getJSON();
$inst->initResponseArray();
}
/**
@ -532,6 +527,25 @@ class egw_json_response
return json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
}
public function json_encode($var)
{
$ret = json_encode($var);
if (($err = json_last_error()))
{
static $json_err2str = array(
JSON_ERROR_NONE => 'No errors',
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
);
error_log(__METHOD__.'('.array2string($var).') json_last_error()='.$err.'='.$json_err2str[$err]);
}
return $ret;
}
/**
* Function which can be used to add an event listener callback function to
* the "beforeSendData" callback. This callback might be used to add a response