-1

How can I use jquery's get function to reload the content of the page without doing a full page 'refresh', so that I could stay on the page but it would automatically update any changes?

Basically use jQuery's $.get, then make the page's html the html returned by $.get

But how would I do this? Thanks

Sam
  • 97
  • 5
  • 1
    by code, I suppose, which you aren't showing us – Amit Joki May 12 '14 at 02:22
  • I don't know how to make this; which is why I am asking for help; I am pretty new to jQuery – Sam May 12 '14 at 02:24
  • 1
    possible duplicate of [Ajax tutorial for post and get](http://stackoverflow.com/questions/9436534/ajax-tutorial-for-post-and-get) – Se0ng11 May 12 '14 at 02:27
  • 1
    Sounds like you need a jQuery and AJAX tutorial, not a question on StackOverflow. After you study up on some tutorials and try to do it yourself, come back with a specific question if you get stuck. We'd love to help! – Ayman Safadi May 12 '14 at 02:30
  • `it would automatically update any changes` judging from this your actually refreing to: websockets – Viscocent May 12 '14 at 02:32

1 Answers1

1

It would be something like this, though it is hard to give you guidance without more details. The example below queries a URL every 15 seconds, and if the response is different than the previous request it will update content on the page dynamically.

var previousData = "";
setInterval(function(){
    $.get("http://dariuscode.com/junk/ajaxdemo.php", function(data) {
        if(data != previousData) {
            $("#theContent").html(data);
            previousData = data;
        }
    });
}, 15000);

If you'd like a full example see the following fiddle: http://jsfiddle.net/BgPb5/

Please note if you need truly real-time updates on changes you'll need to use something that creates a persistent connection, not AJAX.

Darius Houle
  • 475
  • 3
  • 8