2016-03-23 17 views
0

次のスクリプトを使用して、データベースから基礎となるレコードを正常に削除しています。しかし、確認をクリックすると、何も起こりません。私は両方のポップアップを閉じてからブラウザでF5キーを押して結果を確認する必要があります。私は多くのことを試してみたが、私はBELOWコントローラのコード JQUERYがポップアップを閉じず、ページを更新しない

ここ

function deletePayment(customerPaymentId) { 
    //alert(customerPaymentId); 
    bootbox.confirm("Are you sure? This payment will be logically deleted", function (result) { 
     if (result) { 
      var url = '/CustomerPayment/Delete'; 
      var data = { 
       id: customerPaymentId 
      }; 

      $.post(url, data, function() { 

       window.location.reload(); 
      }); 



     } 
    }); 
    return false; 
} 
を欠けている単純なものでなければなりません:

//[HttpPost, ActionName("Delete")] 
//[ValidateAntiForgeryToken] 

//[Authorize(Roles = "Delete")] 
public ActionResult Delete(int id) 
{ 

    CustomerPayment obj = _db.GetCustomerPayment(id); 

    _db.Edit(obj); 

    obj.TransactionDateTimeEnd = DateTime.Now; 
    _db.Save(); 




    return View("Index", new { id = obj.CustomerId}); 
} 
+0

返品虚偽?また、あなたはJqueryを含むと確信していますか? – KyleK

+0

$ .postのjqueryドキュメントを見てください:http://api.jquery.com/jquery.post/ あなたは$ .postの 'success'ハンドラだけを実装しています。 200(OK)ステータスコードで復帰)、ウィンドウは決して再ロードされません。 –

+0

ページをリロードするために 'window.location.reload();'を呼び出すだけの場合、ajaxを使用することは全く意味がありません。 –

答えて

0

ここでは、私がテストした正しいコードです。

戻り値falseを削除して明示的に成功と失敗のコールバックを付加している以下のようなajax呼び出しを行うように指示します。

$(document).on("click", ".alert", function (e) { 
      bootbox.confirm("Delete payment ???", function (result) { 
        if (result) { 
         alert('delete fired'); 
         $.ajax({ 
          type: "GET", 
          url: "Jquery-datatable.aspx/GetJsonEmps", 
          data: "{}", 
          dataType: "json", 
          contentType: "application/json; charset=utf-8", 
          success: function (response) { 
           alert('ok'); 
           location.reload(); 
          }, 
          error: function (xhr, ajaxOptions, thrownError) 
          { 
          alert(xhr.responseText); 
          location.reload(); 
          }  
         }); 
        } 
       }); 
      }); 

注:私はすぐにtesting.Youのために上記の例POSTと要求urlにrquest種類を交換し、dataパラメータを追加する必要がチェックしています。コントローラ

public JsonResult Delete(int? id) 
     {   
      if (isSuccess) 
       return Json(new { Success = true, Message = "" }, JsonRequestBehavior.AllowGet); 
      else 
       return Json(new { Success = false, Message = error }, JsonRequestBehavior.AllowGet); 
     } 

とスクリプトのために

0

は線の下に追加

window.location.href = window.location.href; 

は、何か質問があるなら、私に教えてください。

関連する問題