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>
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.
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
hhhhhhhhhhhhhhhhhhhhh
how to stop page from reloading (this causes form to resubmit) ?
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
thank you
Simple and solve my question, tnx
How to reload the page without cache ?
location.reload(true); The parameter tells it to reload from server.
Thank you so much!
Your site is always a big saver.
Thank you..How can I refresh jsp page only one time and don’t refresh it again?
Nice and quick way to reload the page. Thanks for sharing!
I quite like reading a post that can make people think.
Also, thank you for permitting me to comment!
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
Very useful, thanks
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
Great jaspreet
a
[…] Taken from : http://www.mkyong.com/jquery/how-to-refresh-a-page-in-jquery/ […]
I wold like to load only particular div. please help me out.
Thanks in advance.
Then you probably need AJAX (but it is a bit more complicated than this example).
same for me, i want to refresh only a part, how can i do that? help me out
thanks
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 »
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’);
});
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’.
JQuery is based on js, i second mk yong in showing how js can be called using query.
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
thanks for the post, useful
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??
refresh calls ready function, use ur db get there in ready function
[…] Page refresh with jQuery Refresh a page with jQuery location.reload(); […]
Hello Friends,
Watch the latest video tutorial of the jquery, android, phonegap app.
http://youtube.com/webboostings
Thank You
Abhishek