Gidimotje Gidimotje - 1 year ago 80
jQuery Question

Update data on a page without refreshing

I have a website where I need to update a status.
Like for a flight, you are departing, cruise or landed.
I want to be able to refresh the status without having my vieuwers to have and reload the whole page. I know there is a way with AJAX and jQuery, but I don't have any understanding of how that works. I allso don't want them to have and click a button.
If any body knows how that would be done I much appreciate it!

Answer Source

In general, if you don't know how something works, look for an example which you can learn from.

For this problem, consider this DEMO

You can see loading content with AJAX is very easily accomplished with jQuery:

    // don't cache ajax or content won't be fresh
    $.ajaxSetup ({
        cache: false
    var ajax_load = "<img src='' alt='loading...' />";

    // load() functions
    var loadUrl = "";

// end  

Try to understand how this works and then try replicating it. Good luck.

You can find the corresponding tutorial HERE


Right now the following event starts the ajax load function:


You can also do this periodically: How to fire AJAX request Periodically?

(function worker() {
    url: 'ajax/test.html', 
    success: function(data) {
    complete: function() {
      // Schedule the next request when the current one's complete
      setTimeout(worker, 5000);

I made a demo of this implementation for you HERE. In this demo, every 2 seconds (setTimeout(worker, 2000);) the content is updated.

You can also just load the data immediately:


Which has THIS corresponding demo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download