مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

مهدی الهی

عضویت از 1396/07/29

نمایش پیام تائید حذف

  • جمعه 3 آذر 1396
  • 11:25
تشکر میکنم

من میخواستم وقتی رو حذف کیلک کرد با 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');

                }


            });
            }
        })


    }

پاسخ های این پرسش

تعداد پاسخ ها : 4 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • جمعه 3 آذر 1396
  • 12:41

نمونه زیر رو ببینید

 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");
                }
            });
        }

کاربر سایت

مهدی الهی

عضویت از 1396/07/29

  • جمعه 3 آذر 1396
  • 13:21

ممنون
ولی چه کدی بنویسم بعد از Confirm که به طور ajax به کنترلر دیلیت بره و دیلیت کنه اون id  رو ؟

کاربر سایت

مهدی الهی

عضویت از 1396/07/29

  • شنبه 4 آذر 1396
  • 10:11

از این کد هم استفاده کردم ولی  ارور میده 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");
            });
        });
    }

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • شنبه 4 آذر 1396
  • 11:55

این ارور سمت سرور هست و به اسکریپتتون مربوط نمیشه

کدتون رو Trace کنید تا مشکل رو پیدا کنید

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)