I have a jQuery ajax function that posts to a PHP script which then retrieves some fields from the database and returns them to the client. The ajax function is run every 5 seconds after a button is clicked:
window.setInterval(function()
{
ajaxCall("lobby");
}, 5000);
The ajax function:
function ajaxCall(param)
{
$.ajax({
url: "script/lobby.php",
type: "post",
dataType: "json",
data: param,
success: function(data, textStatus, jqXHR){
//do stuff with data
},
error:function(jqXHR, textStatus, errorThrown){
//show error
}
});
}
Is this a good way of doing it? I have read somewhere that if done wrongly it may create a backlog of calls. How would I prevent that or is there a better way instead of querying a database every 5 seconds for each user?