Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery : Refresh/Reload the page on clicking a button

I have a button which loads after a ajax call , on clicking i want to reload the page (like i press f5)

I tried

$( ".delegate_update_success" ).click(function() {
    location.reload();
});

but it does a simple refresh, but my page does not makes a new request to get the contents. It should happen just like I am entering URL to get that page.

like image 984
monda Avatar asked Oct 06 '13 10:10

monda


People also ask

How can I refresh a page with jquery?

Method 1: Using the location. reload(): The location. reload() method reloads the current web page emulating the clicking of the refresh button on the browser.

How can I tell if jquery is refreshing a page?

On Refresh/Reload/F5: If user will refresh the page, first window. onbeforeunload will fire with IsRefresh value = "Close" and then window. onload will fire with IsRefresh value = "Load", so now you can determine at last that your page is refreshing.

What is location reload in jquery?

Window location. The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.


4 Answers

You should use the location.reload(true), which will release the cache for that specific page and force the page to load as a NEW page.

The true parameter forces the page to release it's cache.

like image 57
Royi Namir Avatar answered Oct 10 '22 20:10

Royi Namir


If your button is loading from an AJAX call, you should use

$(document).on("click", ".delegate_update_success", function(){     location.reload(true); }); 

instead of

$( ".delegate_update_success" ).click(function() {     location.reload(); }); 

Also note the true parameter for the location.reload function.

like image 35
Lloyd Banks Avatar answered Oct 10 '22 20:10

Lloyd Banks


Use document.location.reload(true) it will not load page from cache.

like image 24
Anuj Aneja Avatar answered Oct 10 '22 20:10

Anuj Aneja


You can also use window.location.href=window.location.href;

like image 37
Satpal Avatar answered Oct 10 '22 21:10

Satpal