I am putting together an online radio station, and I am using Applescript to update my server with the “nowplaying” information that is ultimately coming from iTunes.
Applescript pushes that information to the server as a .html file.
That works fine, then I receive the information into my website using this line of php:
$fp = fopen ("music/rtl.txt","r");
if (!feof($fp) )
{
$buffer = fgets($fp, 1024);
print "<tr><td align=\"center\"><b>Current Track</b>: $buffer";
}
fclose ($fp);
My question is: how do I get this information to udpate automatically? Even though it is updating on the server, it will remain still until I hit refresh on the webpage.
How do I get this PHP information to refresh itself without having to manually refresh my screen? How can the Current Track information change automatically?
First off, on your html page, use a span with an id to indicate the spot where you want the track info to go:
Then, assuming jquery is cool, use the
ajaxfunction inside a custom function, then usesetIntervalto run it every 5 seconds:And of course, your ajax page will look pretty much like what you’ve got, except take away the html markup, because what it spits out will go between the
<span>tags: