0

How can I refresh a page with JQuery at set intervals that would work like meta refresh but without reloading the page?

...Or reloading an html form on the page to refresh the data it displays?

Either of those would work but I cannot find anything that actually works.

Thanks!

2 Answers 2

1

You can use ajax to update certain fragments of the page using the $.ajax or $.getJSON functions, these functions will call your server side code and retrieve a json block, the json data can then be populated

$.ajax({ url: "mydomain.com/url", type: "POST", dataType: "xml/html/script/json", data: $.param( $("Element or Expression") ), complete: function(data) { var tag = $('#idonpage'); tag.text(data.something.etc); }, success: function() { //called when successful }, error: function() { //called when there is an error }, }); 

or you can use the $.load function using the form $.load('someurl #id'), jQuery will parse the html from someurl looking for the id tag and this data can be used to populate somewhere on your page.

to call a function at given intervals use the javascript setInterval function for example calling a function every 2 seconds :-

setInterval(function() { do something... },2000);

use the document ready function before setting all if this up.

$(document).ready(function() { }); 

Hope this points you in the right direction.

Sign up to request clarification or add additional context in comments.

Comments

1

To refersh whole page you need:

widnow.location.href = "stackoverlow.com"; 

If you need referesh some part of page seems you need take a look into $.ajax

If you want referesh some part of page each 2 seconds use setInterval and $.ajax:

setInterval(function() { $.ajax(..); }, 2000); 

2 Comments

why do i have to call a page if i am already on the page? also, which part sets the interval? Thanks
@usnidorg: I am not suggest to reload page, i just trying to undestand you question and give you all options thats you may need.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.