Created
November 22, 2013 21:14
-
-
Save dgrigg/7606996 to your computer and use it in GitHub Desktop.
A CodeIgniter helper function for returning JSON errors messages to AJAX calls instead of standard HTML error page. Use the helper instead of having to override the core Exception class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
function show_json_error($message, $status_code = 500, $status_message = '') | |
{ | |
header('Cache-Control: no-cache, must-revalidate'); | |
header('Content-type: application/json'); | |
set_status_header($status_code, $status_message); | |
echo json_encode( | |
array( | |
'status' => FALSE, | |
'error' => 'Server Error', | |
'message' => $message | |
) | |
); | |
exit; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment