用户点击删除按钮后,我的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错误代码均可供使用。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top