SORU
10 NİSAN 2012, Salı


Dil eklentisi göndererek Kullanarak durdurmak formu

Eğer doğrulama başarısız olursa göndererek formumu durdurmaya çalışıyorum. Ama benim için çalışmıyor previous post bu kadar takip etmeye çalıştım. Neyi kaçırıyorum?

<input id="saveButton" type="submit" value="Save" />
<input id="cancelButton" type="button" value="Cancel" />
<script src="../../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {
        $("form").submit(function (e) {
            $.ajax({
                url: '@Url.Action("HasJobInProgress", "ClientChoices")/',
                data: { id: '@Model.ClientId' },
                success: function (data) {
                    showMsg(data, e);
                },
                cache: false
            });
        });
    });
    $("#cancelButton").click(function () {
        window.location = '@Url.Action("list", "default", new { clientId = Model.ClientId })';
    });
    $("[type=text]").focus(function () {
        $(this).select();
    });
    function showMsg(hasCurrentJob, sender) {
        if (hasCurrentJob == "True") {
            alert("The current clients has a job in progress. No changes can be saved until current job completes");
            if (sender != null) {
                sender.preventDefault();
            }
            return false;
        }
    }

</script>

CEVAP
10 NİSAN 2012, Salı


Yine, AJAX uyumsuz. ShowMsg işlevi, sunucu ve form olay gelene kadar beklemez gönder AJAX başarı sadece başarı tepki sonra çağrılır.

Tıklatma işleyicisi e.preventDefault(); olarak ilk satırı taşıyın.

$("form").submit(function (e) {
      e.preventDefault(); // this will prevent from submitting the form.
      ...

Kod aşağıda, bakın

== HasJobİnProgress Yanlış izin istiyorum

$(document).ready(function () {
    $("form").submit(function (e) {
        e.preventDefault(); //prevent default form submit
        $.ajax({
            url: '@Url.Action("HasJobInProgress", "ClientChoices")/',
            data: { id: '@Model.ClientId' },
            success: function (data) {
                showMsg(data);
            },
            cache: false
        });
    });
});
$("#cancelButton").click(function () {
    window.location = '@Url.Action("list", "default", new { clientId = Model.ClientId })';
});
$("[type=text]").focus(function () {
    $(this).select();
});
function showMsg(hasCurrentJob) {
    if (hasCurrentJob == "True") {
        alert("The current clients has a job in progress. No changes can be saved until current job completes");
        return false;
    } else {
       $("form").unbind('submit').submit();
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • 3DS Max Tutorials

    3DS Max Tuto

    4 AĞUSTOS 2013
  • Eric Anthony

    Eric Anthony

    13 AĞUSTOS 2011
  • monkophile

    monkophile

    25 Temmuz 2007