问题 如何使用PHP发送服务器错误响应?


用户点击后立即 删除按钮 我的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
 }
);

2245
2017-10-27 16:45


起源



答案:


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

查看 header()函数 了解更多选择。所有HTTP错误代码均可供使用。

相关问题: 如何使用ASP.NET MVC在jQuery AJAX调用中触发“错误”回调?


13
2017-10-27 16:52