Is there away where i can refresh the page without the vistor using it for example i want to refresh the part of a function i guess you could call it refreshing the page but only for the displaying of function refresh();
the kind of function i am looking for is somthing like this.
REFRESH(page(),1000);
abit like javascripts set time out but is there one for PHP itself?
i found this in a tutorial which i am playing around with but how can i get it to display somthnig every minute non-stop?
?>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
function timedCount()
{
document.getElementById('output').value=c;
c=c+1;
t=setTimeout("timedCount()",6000);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
</script>
<?
PHP aint gonna do it because once it leaves the server PHP loses control.
You can use setInterval and an Ajax call (Javascript) to get new content to replace the current page.
jQuery isn’t my first language so that code might not be perfect, but should give you a starting point.
Replace your-server-script.php with the URL of your server side script. It should return the HTML that will become the content of your <body> tag.
If you just want to update part of the document change the selector from “body” to something more specific (e.g “#someElementID”)
jQuery is a Javascript library that simplifies a lot of common JS programming tasks such as selecting elements in the DOM, handling events (click, mouseover), running Ajax transactions, doing animation etc.
Ajax is the process of getting data from the server to the browser or page without reloading the whole page. jQuery provides functions to manage Ajax transactions (as do all JS libraries).
$(“body”).html(data) means this:
$ is the jQuery object (shortcut).
“body” is a HTML selector (same as you might use in CSS). In this case it will get all <body> tags, of which there should be exactly 1.
data will be the response from your server side script (the data of the ajax transaction) and the .html() function call will set the innerHTML of <body> to that data.
That line of code will be called when the the Ajax transaction finishes, and it will set the content of <body> to be whatever your .php script displays.
definitely here at Sitepoint - not sure whether I always like the helpfulness of Sitepoint members, it makes people lazy, and if you don’t help as much as those regulars, you’re seen as unfriendly…
Luckily I don’t care about being perceived as unfriendly. But yes, the culture here does seem to make people entirely dependent on hand-outs which actually harms them rather than helps.
You need to close the first script and open another
<script type=“text/javascript” src=“jquery-1.3.2.min.js”></script>
<script type= …>
//your code here
</script>