Refresh a div with jQuery

谁说胖子不能爱 提交于 2019-12-01 23:15:44

You can dynamically change the contents of the signup div with jquery as follows:

$("#signup").html("My New Login Section");

or

var $loginDiv = $(document.createElement("div")).html("<label>Username</label><input type='text' id='username'/>");
$("#signup").html($loginDiv);

Use load()

$('#signup').load('php/logout.php', function() {
  alert('Logout.');
});

I'd try:

$('#logoutbtn').on('click', function () {    
    $.ajax({  
        type: "POST",  
        url: "php/logout.php"
    })
    .done(function(data){
        $('#signup > h3').html('Please <button id="loginbtn" class="submitButton">Login</button>');
    });
})

The same approach could be used for the login action to prevent the page from having to refresh.

as you have your session method inside of your tag, you can do on success event following:

success: function(data){
        $("#signup").load(".register");
    } 

it will reload everything inside of < div id="signup" class="register"> and as you've removed your session (i suppose), than it will be reload to your login/logout form.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!