我在javascript中使用此代码显示rss:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jQuery RSS Reader</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
<script type="text/javascript" src="js/jquery.jfeed.pack.js"></script>
<script type="text/javascript" src="js/jquery.flips.min.js"></script>
<script type="text/javascript">
jQuery(function() {
jQuery.getFeed({
url: 'last_20_reports.php',
success: function(feed) {
var html = '';
for(var i = 0; i < feed.items.length && i < 20; i++) {
var item = feed.items[i];
html += "<div class='block'>"
// Gets the RSS link and title
+ '<h3>' + item.title + '</h3>';
html += item.description + '<br><br>';// Gets the RSS description
html += "<div class='grey'>"
// Gets the RSS pubDate
+ 'από ' + item.author +'<br>'
+ 'στις ' + item.updated
+ '</div>';
// Gets the RSS category
//html += item.category
html += '</div>';
}
jQuery('#latestnews').append(html);
// Adds the jQuery Flips element. The direction can left, top or bottom/
$('#news').flips( { autorun_delay:1000, direction: 'right'});
}
});
});
</script>
</head>
<body>
<div class="to-flips" id="news">
<h1>Πρόσφατες αναφορές</h1>
<div class="content">
<div id="latestnews"></div>
</div>
<div class="flipnav"></div>
</div>
</body>
</html>
显示每个项目的元素标题和描述,但作者和类别显示为未定义。你能帮助我吗?
xml''file''(last_20_reports.php)是:
<?php
header ("Content-Type: application/xml;");
$db_host = "***";
$db_username = "***";
$db_pass = "***";
$db_name = "dhmos_patras_db";
$con = mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to mysql");
$sel = mysql_select_db("$db_name") or die ("No database");
$sql = "SELECT * FROM reports INNER JOIN categories ON reports.categoryID = categories.categoryID INNER JOIN members ON reports.userID = members.memberID ORDER BY submit_date DESC LIMIT 0, 20";
$result = mysql_query ($sql,$con);
//xml
echo '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<feed xmlns="http://www.w3.org/2005/Atom">';
echo '<channel> ';
while($row = mysql_fetch_array($result))
{
echo '<item>';
echo '<title>'.$row['title'].'</title>';
echo '<description>'.$row['description'].'</description>';
echo '<pubDate>'.$row['submit_date'].'</pubDate>';
echo '<category>'. $row['category_name'] .'</category>';
echo '<author>'. $row['username'] .'</author>';
echo '</item>';
}
echo '</channel>';
echo '</feed>';
echo '</rss>';
?>
提前致谢并抱歉我的英语!