-1

当页面第一次加载时,我在 Jquery.ready 上加载的页面内容完美运行,然后当我使用 ajax 做一些事情并尝试再次加载页面时,javascript 在我尝试加载的第二个页面上不起作用。我试图通过使用live()/on()方法来解决这个问题,但没有奏效。

$(document).ready(function () {
    $("#grupyonetimarea").load("/Panel/MusteriSourcePages/mus_grup_add.aspx");
});

$('#btnekleme').live('click', function () {
    $.ajax({
        type: "POST",
        url: "/Panel/MusteriSource/mus_kisiadd.aspx/mus_kisi_kaydet",
        data: "{ad:'" + $.trim($("#txtalt_mus_adi").val()) + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        cache: false,
        before: $("#btnekleme").hide(),
        success: function (msg) {
            if (msg.d == "ok") {
                $("#grupyonetimarea").load("/Panel/MusteriSourcePages/mus_grup_add.aspx");
            } else $("#loaded").html(msg.d).show(500);
        },
        error: function (x, e) {
            alert("The call to the server side failed. " + x.responseText);
        }
    });
}
4

2 回答 2

1

live已弃用,因此使用on()委托事件.. 将其委托给最近的静态父级.. (这可能不是问题,但如果您想在不久的将来更新您的 jquery,则可以安全地使用 on() 以备将来...)..如果您想了解更多信息,请点击此处的链接on()

 $(document).on('click','#btnekleme', function () {.. //using closest static parent element is preferred here than the document

你可以在ajax中将数据作为对象发送

var inputValue= $.trim($("#txtalt_mus_adi").val());
data: {ad:inputValue},
于 2013-03-23T17:23:05.773 回答
0

非常感谢您的所有回答。我就是这样做的,当我运行该函数时,我只是创建了一个函数,即 kontrolet(),它可以很好地工作,这是我想要的。

      $(document).on('click', '#btnekleme', function () {
                    $("#grupyonetimarea").load("/Panel/MusteriSourcePages/mus_grup_add.aspx");
                });

 function kontrolet() {
         $.ajax({
                            type: "POST",
                            url: "/Panel/MusteriSource/mus_kisiadd.aspx/mus_kisi_kaydet",
                            data: "{ad:'" + $.trim($("#txtalt_mus_adi").val()) + "'}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            async: true,
                            cache: false,
                            before: $("#btnekleme").hide(),
                            success: function (msg) {
                                if (msg.d == "ok") {
                                    $("#grupyonetimarea").load("/Panel/MusteriSourcePages/mus_grup_add.aspx");
                                    alert("Kayıt işlemi başarılıdır.!");
                                    TextArealariClearET();
                                    $("#btnekleme").show();
                                }
                                else
                                    $("#loaded").html(msg.d).show(500);
                            },
                            error: function (x, e) {
                                alert("The call to the server side failed. " + x.responseText);
                            }
                        });
        }
于 2013-03-23T19:16:04.237 回答