質問

ユーザーが削除ボタンをクリックするとすぐに、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エラーコードが使用可能です。

関連する質問:どのようにして" error"をトリガーしますかASP.NET MVCを使用したjQuery AJAX呼び出しでのコールバック?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top