1

I have php includes in different divs, how can i use ajax to constantly refresh the data outputted from the php file every second, I have multiple things that need to refresh, one per div

2
  • 2
    And what you have tried yet apart from posting this question on SO? Commented Dec 27, 2016 at 5:44
  • I have tried methods but they did not let me have all the divs and php files to refresh in one function Commented Dec 27, 2016 at 5:48

2 Answers 2

2
  1. Use the javascript function settimeout
  2. In the setimeout function, perform the ajax request
  3. Fill the div element with the results from the ajax request
  4. Again, use the settimeout function in the ajax response and perform the step 2 and 3.
Sign up to request clarification or add additional context in comments.

2 Comments

Please don't ask for upvotes/accepts as it's not considered as constructive. See: Is it acceptable to ask for upvote/accept in an answer when submitting it?
I'm planning out the design for a real-time game, and I was wondering, how often should the setimeout be? I want it to be real-time, but would having a delay of 0 lag up the server?
0

send a ajax request per second.

window.setTimeout(function () {
    $.ajax({
        // param
    });
}, 1000);

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.