Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reload div after ajax request

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

function Register(event) {
event.preventDefault();
    console.log(event);
    $.ajax({
        type: 'POST',
        url: register,
        data: {
            name: $('#name').val(),
            email:   $('#Email').val(),
            password: $('#password').val(),
            _token: $('#token').val()
        },
        dataType : "json",

        success: function (data) {
           if (data.success){

             $('#header').
               $('#Register').modal('hide');

           }
        }
    });

}

i need reload or refresh the header div.

like image 256
Reco Jhonatan Avatar asked Jul 07 '16 05:07

Reco Jhonatan


People also ask

How do I load a div after Ajax success?

Just reload the header.

How do you reload the same page after Ajax success?

You can use the location. reload() method to reload or refresh an entire web page or just the content inside an element. The . reload() method can be triggered either explicitly (with a button click) or automatically.

How reload page after Ajax call in MVC?

So the page needs to refresh after an ajax call….. In the controller action build the redirect url and include any route parameters that are needed. The Url is returned in the Json object to the calling javascript along with any other values e.g. the result of a database update.


2 Answers

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.

like image 110
Supunsam Avatar answered Oct 12 '22 22:10

Supunsam


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

if (data.success){
   $("#divid").load(" #divid");
    }
like image 32
Sree KS Avatar answered Oct 13 '22 00:10

Sree KS