3

Possible Duplicate:
Javascript hard refresh of current page

Is there a way to refresh a page using javascript? I'm using jQuery Mobile to display some statistics in a listview (probably a listview), and I need to re-populate the data from a MySQL db every 10 seconds, let's say. Is this possible?

Thanks in advance.

Community
  • 1
  • 1
Apollo
  • 8,874
  • 32
  • 104
  • 192

2 Answers2

6

If you're using JQM use the listview.('refresh') method on a list view. Use ajax and call .refresh() on the list in the handler.

$.ajax({ /* code goes here */ 
 success : function(e) { for (var i in e.data) 
 { listView.add(i); } 
   listview.listview('refresh'); });

FROM JQM Docs: http://jquerymobile.com/test/docs/lists/docs-lists.html Updating lists If you add items to a listview, you'll need to call the refresh() method on it to update the styles and create any nested lists that are added. For example:

$('#mylist').listview('refresh'); Note that the refresh() method only affects new nodes appended to a list. This is done for performance reasons. Any list items already enhanced will be ignored by the refresh process. This means that if you change the contents or attributes on an already enhanced list item, these won't be reflected. If you want a list item to be updated, replace it with fresh markup before calling refresh.

The Internet
  • 7,959
  • 10
  • 54
  • 89
2

I'd recommend using ajax for this. But to refresh a page in JS, just do:

window.location.reload();

or

window.location.href = window.location.href;

Marshall
  • 4,716
  • 1
  • 19
  • 14
  • The first works for me in IE and Chrome (didn't test it on others), but the second method didn't work in either browser? – Jeach Apr 12 '13 at 13:05
  • I confirm that `window.location.reload()` works in Microsoft Edge and Google Chrome for the simple case of refreshing the whole page. – Mike Finch Oct 20 '21 at 20:57