reload div after ajax request

前端 未结 3 1677
无人共我
无人共我 2020-12-31 15:44

how i can refresh or reload a div after ajax request? i have this code:

function Register(event) {
event.preventDefault();
    console.log(event);
    $.ajax         


        
相关标签:
3条回答
  • 2020-12-31 15:55

    I know this post is old and already answered. But I would Like to add something to it. If you look at the answer of @Sree KS it will load the div on top of the existing div. Which is not ideal. Just run inspect div after the method is completed.

    To avoid this issue use the following code:

    $("#divid").load(" #divid > *");
    

    Hope this will help to anyone who has the same issue.

    0 讨论(0)
  • 2020-12-31 15:56

    I think you are trying to reload the header section after login to show the username, logout etc. To do that you have to return the all html from the your ajax method into the "data.success" variable using like json encode.

    your ajax method function () {
        $response = array('success' => 'Your html data come here');
        echo json_encode($response);
        exit(0);
    }
    
    0 讨论(0)
  • 2020-12-31 16:09

    You can load the div like this.Please mind the space before divid (" #divid");

    if (data.success){
       $("#divid").load(" #divid");
        }
    
    0 讨论(0)
提交回复
热议问题