Ajax loop updater

qlithe

Supreme Member
Joined
Feb 14, 2012
Messages
1,252
Reaction score
288
Hey

I need a way to constantly update my users balance and update a column in my database called "last activity". I'm considering something like this:
Code:
    $(document).ready(function(){
  
        function update()
        {
            $.ajax({
                    type:"post",
                    url:"update.php",
                    data:formData,
                    dataType: 'text',
                    success:function(data){
                  
                      // get balance from mysql

                      // update column in mysql

                    },
                    complete:function(){
                        setTimeout(update, 5000);
                    },
                    global: false
            });
        }
      
        setTimeout(update, 5000);
      
    });

Are there any downsides to this method? Will it be very resource heavy?

Thanks in advance
 
The decision is good.
Note: Calculate only the new balance value on the server side.
 
Yes looks good, but might result in big MySQL load if traffic is high, so make sure your server can handle.
 
Hmm you may have problem with high loads on the server
 
Back
Top