Error at php script didn`t handle by $.ajax
I have these code:
<script>
$.ajaxSetup({
timeout:3000,
success: function(){alert('True!!!');},
error:function (){
alert('false');
}
});
$.ajax({
url:'test.php',
});
</script>
My 'test.php' is:
<?
sleep(8);
$124415;
?>
So it`s have parser error, but ajax return "True" immediately, but if the second line have comment, it waiting for 3 sec. and return "false'. Any ideas ? I have change code test.php:
<?
function shutdown() {
header("HTTP/1.0 500 Internal Server Error");
ob_flush();
}
ob_start();
register_shutdown_function('shutdown');
spl_autoload_register('foo');// Fatal Error => Ajax false
//$112123123;//if turn on will be Parse Error => Ajax true
?>
So now ajax alert开发者_开发技巧 me about fatal error, but Parser Error is not catching. Is anybody know good solution for this problem?
Works as designed.
If there's a parser error, the PHP script will fail and terminate immediately. On the ajax end however, this is still a success because PHP sends a 200 OK
header anyway.
(PHP will send a 500
header for fatal errors only if error_reporting
and display_errors
are turned off.)
If there's no parser error, the script will sleep for 8 seconds, reaching the 3 second timeout, resulting in an Ajax error.
It is normal behaviour: in the first case your php script returns php parse error and ajax gets that, so your ajax went OK.
Next case your php script runs longer than ajax can wait, so your ajax pops up the error.
Cheers Arman.
精彩评论