php - 如何使用 php 发送服务器错误响应?

标签 php ajax jquery response

只要用户单击删除按钮,我的 jQuery 脚本就会要求服务器删除所选项目。

现在我希望我的 php 脚本发送成功或错误响应。

如果项目无法删除,是否可以触发错误回调

谢谢


我的 jQuery 代码:

$.ajax({
 type: "post",
 url: "myAjax.php" ,
 dataType: "text",
 data: {
  some:data
 }, 
 error: function(request,error) 
 {
         // tell the user why he couldn't delete the item
         // timeout , item not found ...
 },

 success: function ( response )
 {
      // tell the user that the item was deleted
         // hide the item
 }
);

最佳答案

header("HTTP/1.0 404 Not Found");
header('HTTP', true, 500); // 500 internal server error
// etc etc.. 

查看 header()更多选项。所有 HTTP 错误代码都可供使用。

相关问题:How do you trigger the "error" callback in a jQuery AJAX call using ASP.NET MVC?

关于php - 如何使用 php 发送服务器错误响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1632159/

相关文章:

php - 找不到基表或 View : 1146 Table Laravel 5

jquery - 如何在jquery中动态调用url?

javascript - mvc $ ('form' ).submit 不在部分 View 上执行

javascript - “data-rel”灯箱不适用于 ajax 内容

javascript - 如何使用 jQuery 管理嵌套类?

php - 'PDOException' 消息 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ' 214748364 7' for key ' contact_no'

php - 如何将这个不整洁的表头排序代码转换为紧凑的函数?

php - 如何在laravel Eloquent 更新查询中更新表字段=字段+1

php - Ajax请求导致服务器崩溃

javascript - 我无法使用 Google 的库(名为 diff_match_patch)比较两个文本文件