How to refresh the auto refresh div inside the div theres is php
The following code dont work?
var refresh = setInterval(function() { $("#recent_activity").html(); }, 1);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Based on x0n’s comment, which I think is a fair guess, I am guessing that you want to automatically refresh a
<div>with content from the server every X seconds. In your example, your second argument to thesetIntervalfunction is 1. This is a really bad idea, as the delay is in milliseconds, so you would be firing off 1000 requests a second (not that the browser would let you, but still).Anyhow, if that’s what you want, you would need to do this:
Your server-side script (
recent_activity_ajax.phpin the example) would then need to return whatever you want the<div>to be populated with – just that, not the headers or footers or anything else. If you wanted this to start when the page loads, you would simply callstartActivityRefresh:If this is not at all what you meant by refreshing the
<div>, you’re going to need to clarify. 🙂EDIT:
In response to your comment: you can’t make Javascript “refresh” the contents of the dynamic PHP code. This just isn’t possible as the browser can’t really execute a server side language like PHP. You have to call the server again. In order to make this cleanest you should probably move the code that fills the contents of
#recent_activityto a function, call that once when the page loads and have a different file that simply outputs that code to be able to refresh it dynamically. You should probably look into MVC patterns from here, but I’m not sure if you’re quite ready for that…