简体   繁体   English

删除ajax加载的页面并保留原始div不起作用

[英]Removing ajax loaded page and retain original div not working


I have the following functionn called when a link is clicked. 单击链接后,将调用以下函数。 The function loads a new page over a div through ajax. 该函数通过ajax在div上加载新页面。

<pre><code>
    function getSummary(id)
{
    loadPage_signup = "new_user.php";
    loadPage_benef = "readercycle_benef.php";
    $.ajax({
      url:"new_user.php",
      dataType: 'html',
      success:function() {
         $("#readercycle_benef_container").load(loadPage_benef);       
         $("#rc_main_header_login").load(loadPage_signup);
      }
    });
}
</code></pre>

In this newly loaded page through ajax, a cancel button exists. 在这个通过ajax重新加载的页面中,存在一个取消按钮。 On clicking this cancel button, the ajax loaded page should be removed and must retain the original div content. 单击此取消按钮后,应删除加载了ajax的页面,并且该页面必须保留原始的div内容。

I wrote the below function that is intended do this functionality. 我编写了以下旨在实现此功能的功能。 But this is not working. 但这是行不通的。 The ajax loaded page is removed, but the original div does not come up with children. 删除了已加载ajax的页面,但是原始的div没有附带子元素。 Please help me understand what went wrong! 请帮助我了解问题出在哪里!

<pre><code>
function closeDiv(id) {
    $(id).remove();
    $ret = $("#rc_main_header_login").show();
    $("#rc_main_header_login").nextAll().show();
}


<input type="button" id="button_cancel" name="btnCancel" value="cancel" onClick="closeDiv('#rc_main_header_newuser')" />
</pre></code>

You need to save the original contents into global variables so you can restore it later. 您需要将原始内容保存到全局变量中,以便稍后进行还原。

jQuery: jQuery的:

var original_content_benef = '';
var original_content_rc = '';

function getSummary(id)
{
    loadPage_signup = "new_user.php";
    loadPage_benef = "readercycle_benef.php";
    $.ajax({
        url:"new_user.php",
        dataType: 'html',
        success:function() {
            // save original content
            original_content_benef = $("#readercycle_benef_container").html();
            original_content_rc = $("#rc_main_header_login").html();
            // replace content
            $("#readercycle_benef_container").load(loadPage_benef);       
            $("#rc_main_header_login").load(loadPage_signup);
        }
    });
}

function closeDiv(id) {
    $(id).remove();
    // restore original content
    $("#readercycle_benef_container").html(original_content_benef);
    $("#rc_main_header_login").html(original_content_rc);
    // do your showing
    $ret = $("#rc_main_header_login").show();
    $("#rc_main_header_login").nextAll().show();
}

HTML: HTML:

<input type="button" id="button_cancel" name="btnCancel" value="cancel" onClick="closeDiv('#rc_main_header_newuser')" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM