views:

244

answers:

1

Hi all,

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
 }
);
+2  A: 
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: http://stackoverflow.com/questions/407651/how-do-you-trigger-the-error-callback-in-a-jquery-ajax-call-using-asp-net-mvc

Mike B