How to refresh a page in jQuery?

To refresh or reload a page with jQuery, you can use the “location.reload();” command.


<html>
<head>
<title>Refresh a page in jQuery</title>
 
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

</head>

<body>

<button id="PageRefresh">Refresh a Page in jQuery</button>

<script type="text/javascript">
	
	$('#PageRefresh').click(function() {

    	      location.reload();

	});

</script>

</body>
</html>

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
24 Comment threads
8 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
27 Comment authors
Peter ChibunnaBenson QSystemsHunterLaxmanPraveen Inbasekaran Recent comment authors
newest oldest most voted
Peter Chibunna
Guest
Peter Chibunna

I disagree with the solution. You simply used jQuery to trigger the click event, then you fall back to JavaScript to do the reload. “location.reload” is not jQuery.

Laxman
Guest
Laxman

Hi all, i have written java script inside jsp for calling Action (i’m using struts2) now it works with mozilla but not working in IE.

function getPopulateData(){
document.searchform.action=”getPopulateData”;
document.searchform.submit();
here getPopulateDate is action name and searchform is form name

ggggggggggggg
Guest
ggggggggggggg

hhhhhhhhhhhhhhhhhhhhh

Praveen Inbasekaran
Guest
Praveen Inbasekaran

how to stop page from reloading (this causes form to resubmit) ?

Srinivas
Guest
Srinivas

hi i want to refresh the Div part where it uses but i want to refresh it on periodically where in that included jsp there is some content is getting from DB. which is dynamically i want to show in this jsp

john
Guest
john

thank you

DougLopesReal
Guest
DougLopesReal

Simple and solve my question, tnx

Hitesh Kumar Dewangan
Guest
Hitesh Kumar Dewangan

How to reload the page without cache ?

Peter Chibunna
Guest
Peter Chibunna

location.reload(true); The parameter tells it to reload from server.

goodbad
Guest
goodbad

Thank you so much!
Your site is always a big saver.

Areeg
Guest
Areeg

Thank you..How can I refresh jsp page only one time and don’t refresh it again?

Free Form Generator
Guest
Free Form Generator

Nice and quick way to reload the page. Thanks for sharing!

cynthia
Guest
cynthia

I quite like reading a post that can make people think.
Also, thank you for permitting me to comment!

Arun
Guest
Arun

Hi,

Nice article. Check the below link for an article on auto refreshing a webpage or embedded pages using JQuery.

http://www.encodedna.com/2013/03/refresh-reload-page-using-jquery.htm

Sarah
Guest
Sarah

Very useful, thanks

Starkbook
Guest
Starkbook

Jquery is mostly used by many designer to give a look like like magic to websites.Here’s a example to make your web page content display a fade in page loading effect.This will give a better look to your page.Lets See how this can be done with code combination.

you can easily check the example of page load with jquery
http://www.starkbook.com/easily-load-page-with-jquery.html

thanks

Ranjit
Guest
Ranjit

Great jaspreet

dhs@dhs.com
Guest
dhs@dhs.com

a

trackback
JQuery – Refresh a Page « Web Development For Beginners

[…] Taken from :  http://www.mkyong.com/jquery/how-to-refresh-a-page-in-jquery/ […]

venky
Guest
venky

I wold like to load only particular div. please help me out.

Thanks in advance.

g00glen00b
Guest
g00glen00b

Then you probably need AJAX (but it is a bit more complicated than this example).

Hunter
Guest
Hunter

same for me, i want to refresh only a part, how can i do that? help me out

thanks

Benson QSystems
Guest
Benson QSystems

you can use setTimeout() function to reload a div after some period of time; $(function(){ var time = 10; // the starting point var testing “”; function inTime(){ // this is the function to autoload you content from page2.php, or page2.txt setTimout(inTime, 1000); .// autoloads for every 1 second if(time == 8){ $.post(“page2.php”,{testing:test}, function(data){ $(“div_id”).html(data); time = 10; // make time back to 10; clearTimeout(inTime); // the system will be loading content every time time = 8; // the system is going to loop from 10 to 8 forever // however if network losts time might go below 7 seconds… Read more »

Bangaru
Guest
Bangaru

refresh will call ready function again, so use below ready function and do db get again in the place of below alert statement like below :

$(document).ready(function(){
$(“#divIdHere”).html(“Your greeting message”);
alert(‘get db content here’);
});

madcow
Guest
madcow

That’s not jQuery; it’s plain old JavaScript. It’s like saying that you can bring up a calculator in Word by clicking the Windows Start button and typing ‘calc’.

Bangaru
Guest
Bangaru

JQuery is based on js, i second mk yong in showing how js can be called using query.

Nathan
Guest
Nathan

Actually he is right. This is just plain Javascript not Jquery. Even with Jquery being based off of Javascript this is still not truly the way to refresh a page in Jquery. Know this because right now I am supposed to eliminate standard Javascript in my code and replace it with Jquery and at the moment this is the only thing I have left to replace(teacher even said it was wrong too). XD

Ilya
Guest
Ilya

thanks for the post, useful

Dion
Guest
Dion

Hello, cool post =D
Guy I’ve got a problem, really huge problem, I load some content from database into a div, it’s an Welcome message, but when I click the refresh button it’s all gone, how can I solve this problem??

Bangaru
Guest
Bangaru

refresh calls ready function, use ur db get there in ready function

trackback
jQuery Tutorials | J2EE Web Development Tutorials

[…] Page refresh with jQuery Refresh a page with jQuery location.reload(); […]

Abhishek
Guest
Abhishek

Hello Friends,

Watch the latest video tutorial of the jquery, android, phonegap app.

http://youtube.com/webboostings

Thank You
Abhishek