Jump to content

Refreshing content in DIV


DJ_CARO

Recommended Posts

Hello.

Can somebody help me?, I'm looking for script either JS or AJAX/Jquery that will only refresh one div in a website and leave the rest not refreshed. I have some code :

<div id="something">
I need this div to refresh every let's say 2 minutes.
</div>
<div id="playerpra"> but I don't want this div to be refreshed
<center><script type="text/javascript" src="http://player.wavestreamer.com/cgi-bin/swf.js?id=00WCD8ZZ9I7KWZYX"></script></center>
</div>
</div>

Thank you in advance for helping me :)

 

Link to comment
https://forums.phpfreaks.com/topic/256761-refreshing-content-in-div/
Share on other sites

think this will work... will require jquery

 

<script type="text/javascript">
function execRefresh() {
	$("#something").load("/content.php?rand="+Math.random());
	setTimeout(execRefresh, 2*60*1000)
}
$(document).ready(function() {
	execRefresh();
});
</script>

 

where content.php is the content to update the div from... math.random just to prevent cache problems

none of them are working :/ here is my full code.. the file is maxxx,play1.php

 

<?php
$nazwa = 'Imprezkamaxxx';
$slogan = 'maxxxymalna dawka muzyki!';
$strona = 'imprezkamaxxx.co.uk';
$typ_muzyki = 'Dance Electronic House Trance Dub Step Hip Hop';

$config['ip'] = "ip";
$config['port'] = "port";	
$config['haslo'] = "password";	

$scfp = @fsockopen($config[ip], $config[port], &$errno, &$errstr, 30);

if (!$scfp)
{
echo '<font face="Verdana" size="2" color="#000000"><b>Docelowy serwer SHOUTcast jest wył±czony!</b></font>';
}
else
{
fputs($scfp,"GET /admin.cgi?pass=$config[haslo]&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");

while(!feof($scfp))
{
	$page .= fgets($scfp, 1000);
}

$loop = array("STREAMSTATUS", "BITRATE");
$y=0;

while($loop[$y]!='')
{
	$pageed = ereg_replace(".*<$loop[$y]>", "", $page);
	$scphp = strtolower($loop[$y]);
	$$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);

	if ($loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE)
	{
		$$scphp = urldecode($$scphp);
	}

	$y++;
}

$pageed = ereg_replace(".*<SONGHISTORY>", "", $page);
$pageed = ereg_replace("<SONGHISTORY>.*", "", $pageed);
$songatime = explode("<SONG>", $pageed);
$r=1;

while($songatime[$r]!="")
{
	$t=$r-1;
	$playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]);
	$playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]);
	$song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]);
	$song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]);
	$song[$t] = urldecode($song[$t]);

	$r++;
}

fclose($scfp);

$skroc = '50';
?>
<html>
<head>
<title>Radio <?php echo "$nazwa - $slogan"; ?> Online player</title>
<style type="text/css">
body {
    margin: 0px;
    padding: 0px;
    text-align: center;
background-color:#b0c4de;
text-align: justify;
font-family:  Tahoma, Arial, Helvetica, sans-serif;
font-size: 11px;
}
#top_belka{
width:100%;
height: 14px ;
background-image:url('images/belka-gora.png');
color: white;
}
.radioname_text{
font-size: 80%;
text-align: center;
}
#websitebelka{
width: 100%;
height: 17px ;
background-image:url('images/websitebelka-part2.png');
color: white;
font-weight: bold;
margin-top: -28px;
}
.strona{
margin-left: 40px;
}
#teraz_grane{
width: 100%;
height: 80px ;
background-image:url('images/background-forterazgrane.png');
}
.radionazwa2{
color: white;
margin-top: -60px;
margin-left: 100px;
font-weight: bold;
}
.nutagrana{
color: white;
margin-top: -6px;
margin-left: 100px;
}
.typ_musy{
margin-left: 100px;
color: #B8B8B8;
}
.button1{
margin-left: 500px;
margin-top: -60px;
}
#div1{
margin-left: 450px;
margin-top: -50px;
}
#bylograne{
background-image:url('images/bylograne.png');
width: 100%;
height: 70px;
margin-top: -10px;
}
.byloini{
color: white;
font-weight: bold;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="whole lot">
<div id="top_belka" >
<p class="radioname_text">Radio <?php echo "$nazwa - $slogan"; ?></p>
</div>
<img src="images/websitebelka-part1.png" />
<div id="websitebelka">
<p class="strona"><?php echo"$strona"; ?> || DJ_CARO / <?php if (strlen($song[0])>$skroc) { echo substr($song[0], 0, $skroc).'...'; } else { echo $song[0]; } ?> </p>
</div>
<div id="teraz_grane"> this div need to reload as the song will change every few minutes
<img src="images/logo1.png" /><p class="radionazwa2">Radio<?php echo"$nazwa"; ?></p><p class="nutagrana"><?php if (strlen($song[0])>$skroc) { echo substr($song[0], 0, $skroc).'...'; } else { echo $song[0]; } ?></p><p class="typ_musy"><?php echo"$typ_muzyki" ?></p>
<div id="div1">
<?php echo "<a href='http://www.youtube.com/results?search_query="; if (strlen($song[0])>$skroc) { echo substr($song[0], 0, $skroc).'...'; } else { echo $song[0]; } echo" ' target='_blank'><img src='images/yt.jpg' width= '40px' height= '20px' border= '0' /></a>"; ?>
<?php echo "<a href='http://soundcloud.com/search?q%5Bfulltext%5D="; if (strlen($song[0])>$skroc) { echo substr($song[0], 0, $skroc).'...'; } else { echo $song[0]; } echo" ' target='_blank'><img src='images/soundcloud-logo.png' width= '40px' height= '20px' border= '0' /></a>"; ?>
</div>
</div>
<div id="bylograne">
<p class="byloini">Juz polecialo:</p> and this 
<p style="margin-left: 5px; margin-top: -6px;"><?php if (strlen($song[1])>$skroc) { echo substr($song[1], 0, $skroc).'...'; } else { echo $song[1]; } ?></p>
<p style="margin-left: 5px; margin-top: -6px;"><?php if (strlen($song[2])>$skroc) { echo substr($song[2], 0, $skroc).'...'; } else { echo $song[2]; } ?></p>
<p style="margin-left: 5px; margin-top: -6px;"><?php if (strlen($song[3])>$skroc) { echo substr($song[3], 0, $skroc).'...'; } else { echo $song[3]; } ?></p>
</div>
<?php }  ?>
<div id="playerpra">
<center><script type="text/javascript" src="http://player.wavestreamer.com/cgi-bin/swf.js?id=00WCD8ZZ9I7KWZYX"></script></center>
</div>
</div>
</body>
</html>

try

 

...
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function execRefresh() {
	$("#teraz_grane").load("/maxxx,play1.php?rand="+Math.random());
	setTimeout(execRefresh, 2*60*1000)
}
$(document).ready(function() {
	execRefresh();
});
</script>
</head>
...

 

assuming maxxx,play1.php is the file you are updating from? and its in the same dir

try

 

...
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function execRefresh() {
	$("#teraz_grane").load("/maxxx,play1.php?rand="+Math.random());
	setTimeout(execRefresh, 2*60*1000)
}
$(document).ready(function() {
	execRefresh();
});
</script>
</head>
...

 

assuming maxxx,play1.php is the file you are updating from? and its in the same dir

doesen't work :/ "maxxx,play1.php" is the file that the div is in, if you know what I'm talking about the whole code with I posted is maxxx,play1.php, the updates comes from shoutcast when song changes, but the div is not refreshing it self.

i'd try making a php file that just has:

 

 

<img src="images/logo1.png" /><p class="radionazwa2">Radio<?php echo"$nazwa"; ?></p><p class="nutagrana"><?php if (strlen($song[0])>$skroc) { echo substr($song[0], 0, $skroc).'...'; } else { echo $song[0]; } ?></p><p class="typ_musy"><?php echo"$typ_muzyki" ?></p>

 

 

and putting the name of that file in

$("#teraz_grane").load("/THE_NEW_FILE.php?rand="+Math.random());

 

set the refresh time to like 5000 (5 seconds) if you want to test it quicker

i'd try making a php file that just has:

 

 

<img src="images/logo1.png" /><p class="radionazwa2">Radio<?php echo"$nazwa"; ?></p><p class="nutagrana"><?php if (strlen($song[0])>$skroc) { echo substr($song[0], 0, $skroc).'...'; } else { echo $song[0]; } ?></p><p class="typ_musy"><?php echo"$typ_muzyki" ?></p>

 

 

and putting the name of that file in

$("#teraz_grane").load("/THE_NEW_FILE.php?rand="+Math.random());

 

set the refresh time to like 5000 (5 seconds) if you want to test it quicker

Thank you so much for helping me it's working :) :) thanks again :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.