من میخواستم وقتی رو حذف کیلک کرد با swal پیامی نشان بده که میخواهید حذف بشه یانه ؟ اگر روی "بله" کلیک کرد حالا بره به اکشن delete
ولی پیام رو نشون میده ولی کلا به اکشن نمیره
<a class="btn btn-warning" onclick="Delete(@item.ForceId)">حذف</a>
function Delete(id) { swal({ title: 'آیا شما مایلید', text: "آیا شما مایلید حذف کنید؟", type: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'بله' }).then(function (result) { if (result.value) { $.ajax({ url: "/Forces/Edit/" + id, type: "Post", data: { id:id, }, dataType: "text/html", async: true, cache: false, sucess: function (data) { alert("ok") }, error: function (xhr) { alert('error'); } }); } }) }
نمونه زیر رو ببینید
function handleDelete(e, stop) { if (stop) { e.preventDefault(); swal({ title: "Are you sure?", text: "You will not be able to recover the delaer again!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete!", closeOnConfirm: false }, function (isConfirm) { if (isConfirm) { swal("Deleted", "", "success"); $('.delete').trigger('click', {}); } else { swal("Cancelled", "", "error"); } }); }
ممنون
ولی چه کدی بنویسم بعد از Confirm که به طور ajax به کنترلر دیلیت بره و دیلیت کنه اون id رو ؟
از این کد هم استفاده کردم ولی ارور میده POST http://localhost:7100/Forces/Delete/52 500 (Internal Server Error) ممنون میشم دوستان
function Delete(id) { swal({ title: "Are you sure?", text: "Are you sure that you want to delete this member?", type: "warning", showCancelButton: true, showLoaderOnConfirm: true, closeOnConfirm: false, confirmButtonText: "Yes, delete it!", confirmButtonColor: "#ec6c62" }, function() { $.ajax({ url: "/Forces/Delete/"+id, type: "POST" }) .done(function(data) { swal({ title: "Deleted", text: "Member has been successfully deleted", type: "success" },function() { location.reload(); }); }) .error(function(data) { swal("Oops", "We couldn't connect to the server!", "error"); }); }); }
این ارور سمت سرور هست و به اسکریپتتون مربوط نمیشه
کدتون رو Trace کنید تا مشکل رو پیدا کنید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)