[eluser]ciKD[/eluser]
After more investigation, I found the problem.
The default error-code 500 which is set before inclusion of error_db is the reason, in my case, browsers did not care about the content if error 500 is found and json-header is set.
If I set the error-code to e.g. 200, the ajax content-type can be added and all is fine. Took me quite some digging in Exceptions.php and database.php though but again I learned more about CI.
Of course it depends on your ajax-framework if you simply want a plain error 500 and handle this exception in javascript when loading the json or handling it via 'successProperty' e.g. in ExtJS and being able displaying more information to user.
New (working) code, can be used also with other errors:
Code:
<?php
// called by ajax? look for http-header
if ((isset($_SERVER['HTTP_X_REQUESTED_WITH'])) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
// found the header
// if $message was an array (e.g. via error_general.php ...)
$message = str_replace('</p><p>', ' - ', $message);
$json_arr = array(
'success' => FALSE,
'message' => trim(strip_tags($heading)) . ' ' . trim(strip_tags($message))
);
set_status_header(200); // if ajax-framework/browser wants this not 500
header('Content-Type: application/x-json; charset=utf-8');
echo json_encode($json_arr);
} else {
// no header found, use normal html
?>
<html>
<head>
<title>Database Error</title>
...