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.
Just reload the header.
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.
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.
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.
You can load the div like this.Please mind the space before divid (" #divid");
if (data.success){
$("#divid").load(" #divid");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With