简体   繁体   中英

How to send a server error response using php?

As soon as the user clicks the delete button my jQuery script asks the server to delete the selected item.

Now I want my php script to send a success or an error response.

Is it possible to fire the error callback in case the item could not be deleted?

Thanks


my jQuery code:

$.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.. 

Check out header() for more options. All the HTTP error codes are available for use.

Related question: How do you trigger the "error" callback in a jQuery AJAX call using ASP.NET MVC?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM