How to catch error with Ajax + php?

For some reason the address on the proces.php it gives an error 500.
But this is not yet important, it is important that even after that the message that the task is set.
And I know that is not delivered.
Please tell me how to correct the code so that when 500ะน error was issued a different message.

function runall() {
closePopup();
$.ajax({
 type: "POST",
 url: "proces.php",
 data: "send_form=3",
});

$(".popupbg").show();
 $(".popup").css('margin-left', ($(window).width() / 2 - $(".popup").width() / 2) + 'px');
 $(".popup").empty().append("<p style="\"width:100%;\"">a Task is queued</p><button class="cancel" onclick="closePopup()">OK</button>").show();
$('#a2').click();
}
June 5th 19 at 21:44
2 answers
June 5th 19 at 21:46
function runall() {
closePopup();
$.ajax({
 type: "POST",
 url: "proces.php",
 data: "send_form=3",
 success: function() {
$(".popupbg").show();
 $(".popup").css('margin-left', ($(window).width() / 2 - $(".popup").width() / 2) + 'px');
 $(".popup").empty().append("<p style="\"width:100%;\"">a Task is queued</p><button class="cancel" onclick="closePopup()">OK</button>").show();
$('#a2').click();
},
 error: function() {
 // show error message
}
});
}
Thanks, what does this mean... to display error, what you need is "// show the error message" write? - kenton_Corkery commented on June 5th 19 at 21:49
well, like so:

error: function() {
$(".popupbg").show();
 $(".popup").css('margin-left', ($(window).width() / 2 - $(".popup").width() / 2) + 'px');
 $(".popup").empty().append("<p style="\"width:100%;\"">an error Occurred when setting tasks in the queue.</p><button class="cancel" onclick="closePopup()">OK</button>").show();
$('#a2').click();
}


either

error: function() {
 alert('an error Occurred when setting the task to the queue')
}
- thurman_Considine commented on June 5th 19 at 21:52
June 5th 19 at 21:48
For some reason the address on the proces.php it gives an error 500.

usually it happens when you turn off the output of errors fatal error. See logs or ini_set('display_errors', 1); insert before the code.
Put, does not help. I will continue to dig, thanks. - kenton_Corkery commented on June 5th 19 at 21:51

Find more questions by tags AJAXPHP