我有一個 ajax 請求在執(zhí)行時它在 PHP 中給出了內部服務器錯誤 500。這是由于數據庫錯誤。我怎樣才能捕捉到這個錯誤,而不是停止執(zhí)行,我需要顯示一條錯誤消息?我使用 Codeigniter 框架。謝謝
2 回答

慕田峪4524236
TA貢獻1875條經驗 獲得超5個贊
您可以在 AJAX 請求中添加錯誤回調,例如:
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
更多信息:https ://api.jquery.com/jquery.ajax/

藍山帝景
TA貢獻1843條經驗 獲得超7個贊
你想把它困在 PHP 中嗎?
如果是這樣,您可以添加一個 try/catch 塊:
try {
// ...
} catch (\Exception $e) { // you can trap a more specific exception related to your DB
// process error and return a message
}
- 2 回答
- 0 關注
- 162 瀏覽
添加回答
舉報
0/150
提交
取消