Q:

How to make jQuery to continously request the same HTTP GET request

I am implementing a software that reads system status with jQuery by using $.getJSON.
The idea is that I am displaying real-time data in browser and want to update the data as often as possible. The server is also running on localhost so theoretically I should be able to get very low latency (at least < 50 ms, even less than 20).
But question is this: how can I implement getJSON with jQuery so that the HTTP GET request will be automatically resend straight after the earlier request was finished?
In my current implementation I have defined an update function:
function updateSimulation() {       
   $.getJSON('/simulation/', function(data) {
      // ..parse data here
   });    
}

And added a callback once every 50 ms:
document.simulationIntervalId = setInterval( "updateSimulation()", 50 );

The problem is that if a request takes longer than 50 ms, several requests will be waiting for a result asynchronously, meaning that if one request takes longer, older data maybe replaced with newer data, which is not desirable.
So basically it means one of the following two solutions could be consider: 1) either when a response arrives, all pending requests could be killed (not optimal), 2) a new request is only sent after the previous one has returned (perhaps optimal solution).
But as always, all comments and answers are much appreciated!

A:

Why don't you call updateSimulation on the success function (the second parameter of $.getJSON) ?
It will do the request after the previous one has finished.

