Tuesday, February 8, 2011

Automatically Div refresh after 6 or few sec (s) in jquery

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function getRandom() {
$("#random").hide();
$("#random").load("rsstoxml.php", '', callback);
}

function callback() {
$("#random").show();
setTimeout("getRandom();", 6000);
}

$(document).ready(getRandom);
</script>

</head>
<body>

<div id="random">
div content Here.......
</div>

</body>
</html>

rss feed to xml /Rss feed convert to xml format data

<?php
error_reporting(E_ALL);

// LOCATION OF THE FEED

$url = 'http://sports.espn.go.com/espn/rss/news';
//$url = 'http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/cricket/rss.xml';

// READ THE FEED
$xml = file_get_contents($url);

// CONVERT THE FEED TO AN OBJECT
$obj = SimpleXML_Load_String($xml, 'SimpleXMLElement', LIBXML_NOCDATA);

// USE AN ITERATOR TO PRINT LINKS WITH THE ITEM TITLES
foreach ($obj->channel->item as $item)
{
$link = (string)$item->link;
$title = (string)$item->title;
$wrap_title= wordwrap($title, 62, "<br />");

$des = (string)$item->description;
$wrap_des = wordwrap($des, 79, "<br />");

if($url=="http://sports.espn.go.com/espn/rss/news")
{
$ini = strpos($wrap_des,"</a>");
$img_cut=substr($wrap_des,$ini);
}
else
{
$img_cut=$wrap_des;
}

echo "<div style='margin:0px auto;padding:0px;border:1px solid green;margin-bottom:20px;background:#CACACA;width:500px;'>";

echo "\n<a href=\"$link\">$wrap_title</a>";
echo "<br />";
echo "<div style='width:500px;'>$img_cut</div>";

echo "</div>";
}

?>