0
$.ajax({
    type: 'POST',
    url: '/test.php', 
    data: {
        'test': 'phptest'
    }//,
    //dataType : 'json'
}).done(function (xhr, status, error) {
    console.log(xhr);
    console.log(status);
    console.log(error);     
    $('#test').html(xhr);
}).fail(function (textStatus, errorThrown) {
    $('#test').html(textStatus+': '+errorThrown)
});

test.php:

<?php

echod $_POST['test'];

?>

Notice I purposely use 'echod' so it throws an error. How can I catch this type of error on return in my done function?

.fail would catch a connection problem to test.php which there isn't.

So, as is, this completes successfully yet my return (xhr) is Parse error: syntax error, unexpected '$_POST' (T_VARIABLE).... which is the error returned from test.php. That is what I want to catch.

user756659
  • 3,372
  • 13
  • 55
  • 110
  • it will be catched in the error function. add `error: function(){}` to see – guradio Apr 24 '19 at 23:21
  • Don't think you are understanding this right. I added a little so maybe it is a little clearer now. – user756659 Apr 24 '19 at 23:48
  • Ignore the accepted answer to the dupe, the second answer shows how you can even catch parse errors. For normal errors you can simply use `set_error_handler()`. – Nick Apr 24 '19 at 23:49

0 Answers0