javascript - Removing ajax loaded page and retain original div not working -



have following functionn called when link clicked. function loads new page on div through ajax.

<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 newly loaded page through ajax, cancel button exists. on clicking cancel button, ajax loaded page should removed , must retain original div content.

i wrote below function intended functionality. not working. ajax loaded page removed, original div not come children. please me understand 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 save original contents global variables can restore later.

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);     // showing     $ret = $("#rc_main_header_login").show();     $("#rc_main_header_login").nextall().show(); } 

html:

<input type="button" id="button_cancel" name="btncancel" value="cancel" onclick="closediv('#rc_main_header_newuser')" /> 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -