Refresh a div with jQuery

前端 未结 4 1318
無奈伤痛
無奈伤痛 2021-01-20 03:27

Is it possible to refresh a single div with jQuery? I have a button that does logout a user. After the button is clicked, I want to show the login form, so I need to re-pars

相关标签:
4条回答
  • 2021-01-20 03:54

    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);
    
    0 讨论(0)
  • 2021-01-20 04:05

    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.

    0 讨论(0)
  • 2021-01-20 04:13

    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.

    0 讨论(0)
  • 2021-01-20 04:16

    Use load()

    $('#signup').load('php/logout.php', function() {
      alert('Logout.');
    });
    
    0 讨论(0)
提交回复
热议问题