0

So right now I am using me of this:

function checkpoints()  { 
  var postThis = 'checker.php?userid='+ $('#user_id_points').val();
  $.post(postThis, function(data){
        $(".vispoints").html(data).find(".vispoints1").fadeIn("slow")
  });
  setTimeout(checkpoints, 5000);
}

This function repeats each 5 seconds (sending request each 5 seconds) and running the checker.php each 5 seconds, to show how many points you got. (checker.php echo out how many points you've got in a span class vispoints1).

Now isnt there a smarter method doing this, instead of sending requests like this all the time.. I mean sites like facebook and that, they dont do like this to check if you e.g got a new friend request?

Hope you can help me find a better method examples would be good too.

2 Answers 2

0
I mean sites like facebook and that, they dont do like this to check if you e.g got a new friend request?

Actually, sites like Facebook do employ polling to get certain notifications. If you're using Firefox, install the Live HTTP Headers plugin and you'll see timed calls to facebook servers.

For your app, polling every 5 seconds is far too much. Scale it back to every couple of minutes. Anything that requires that much "granularity" shouldn't be using javascript but rather a different language that can open a port on the server.

Sign up to request clarification or add additional context in comments.

1 Comment

So i should continue using my function but just instead of 5 seconds have it to 1-2 minutes? I thought it was possible that exactly when you earn points you'll see your new points increase
0

You can look into the ideas which can be found by searching for keywords like

Comet, Ajax Push, Reverse Ajax, ....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.