views:

58

answers:

2

I would like to know what's the best way to limit ajax call / time.

I'm running the following js function when the user mouseover a table row.

function load()
{
    $.ajax({
       type: "GET",
       url: "process/ajax.php",
       data: "action=action,
       success: function(msg)
            {
              if(msg!='')
              {
          displayStuff;
              }

           }
    });
}

Should I create a timestamp and compare it with the previous one?, How can I do that in a global context.

+1  A: 

You can use the javascript Date Object to store the last update time, and check (against a new call to the Date Object) that upon future mouseovers.

Jonathan Sampson
+1  A: 

As a suggestion, why not use the now-famous hoverIntent plugin to prevent the accidental firing of ajax calls on the mouseover event.

karim79