outputjson : display an error message if the json to display is invalid (binary)
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3028 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -4,7 +4,9 @@
|
|||||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||||
|
|
||||||
require_once ("output.php");
|
require_once ("output.php");
|
||||||
/** Display in JSOn the data provided */
|
/** Display in JSON the data provided
|
||||||
|
* The data must NOT be binary !
|
||||||
|
*/
|
||||||
class outputjson extends output
|
class outputjson extends output
|
||||||
{
|
{
|
||||||
/** Don't allow to output in JSON if the functions are not available in PHP */
|
/** Don't allow to output in JSON if the functions are not available in PHP */
|
||||||
@@ -25,7 +27,11 @@ class outputjson extends output
|
|||||||
@header('Cache-Control: post-check=0, pre-check=0', false);
|
@header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
@header('Pragma: no-cache');
|
@header('Pragma: no-cache');
|
||||||
@header ("Content-Type: application/json");
|
@header ("Content-Type: application/json");
|
||||||
echo json_encode ($data);
|
$content = json_encode ($data);
|
||||||
|
if (json_last_error () !== 0)
|
||||||
|
printf (dgettext("domframework", "Can't send in JSON invalid data : %s"),
|
||||||
|
json_last_error_msg ());
|
||||||
|
echo $content;
|
||||||
if (!defined ("PHPUNIT"))
|
if (!defined ("PHPUNIT"))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user