【问题标题】:load page into a div将页面加载到 div
【发布时间】:2013-03-23 17:19:38
【问题描述】:

当页面第一次加载时,我在 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);
        }
    });
}

【问题讨论】:

    标签: jquery jquery-load


    【解决方案1】:

    live 已弃用,因此请使用 on() 委托事件.. 将其委托给最近的静态父级.. (这可能不是问题,但如果您想更新 jquery,则可以安全地使用 on() 以备将来使用在不久的将来...)..这里是link,如果您想了解更多关于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},
    

    【讨论】:

    • 我试图通过使用 live() / on () 方法来解决这个问题,但是没有成功。
    • 我做到了。因此,我将特定的引用放在评论中。你必须提到你也委托了内容。
    • 是的 .. 谢谢... 我更新了.. :).. 我认为如果我们稍后尝试更新他的 jquery 以防万一... :).. 无论如何谢谢
    【解决方案2】:

    非常感谢您的所有回答。我就是这样做的

          $(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);
                                }
                            });
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多