jQuery AJAX的最简单形式

How to send the simplest form of jQuery AJAX request to the server every 60 seconds to keep the user status as ACTIVE while the page is still open.

There is no need to get any response back from the server:

setInterval(function() {
    $(document).load('path/to/keep-user-active.php');
}, 60000);

Then the PHP script will do the necessary.

Simple AJAX w/ JQuery. Note you don't have to do anything with the result but whatever you do want to do with it, put code where #div1 is.

setInterval(function() 
{
       $.ajax({url: "path/to/keep-user-active.php", success: function(result){
       $("#div1").html(result);
       }});
}, 60000);

Simplest jQuery way is by using $.get(). If you don't need the response, just add the url without any callbacks.

setInterval(function() {
    $.get('path/to/keep-user-active.php');
}, 60000);

This example calls path/to/keep-user-active.php, and sends the response through the success() function. Replace #ajax-result with the div where you want your output to appear.

setInterval(function() {
    $.ajax({
        url: "path/to/keep-user-active.php",
        success: function(data) {
            $("#ajax-result").html(data);
        }
    });
}, 60000);

Well... If you want to ignore the result and just use it as heartbeat, then this will be the easiest form, I guess:

setInterval(function() {
    $.get( 'path/to/keep-user-active.php' );
}, 60000);

But... If it is used for checking if user is online, then cache may be a problem... So this may work a little bit better:

setInterval(function() {
    $.ajax({
        url: 'path/to/keep-user-active.php',
        cache: false
    });
}, 60000);