有没有任何 jQuery 插件可以创建类似实时 feed 的东西推特主页 http://www.twitter.com,使用 PHP,它从 MySQL 数据库获取数据?
PHP 文件必须如何?
Thanks.
您确实不需要为此使用插件,您可以使用 jQuery 轻松创建类似的东西来对 PHP MySQL feed 进行 AJAX 调用
创建一个脚本以使用以下命令进行重复的 AJAX 调用设置超时() http://www.w3schools.com/jsref/met_win_setinterval.asp然后使用以下命令将新找到的结果添加到 feed 容器中.prepend() http://api.jquery.com/prepend/
HTML
<html>
<head><title>Tweets</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style>
#tweets {
width: 500px;
font-family: Helvetica, Arial, sans-serif;
}
#tweets li {
background-color: #E5EECC;
margin: 2px;
list-style-type: none;
}
.author {
font-weight: bold
}
.date {
font-size: 10px;
}
</style>
<script>
jQuery(document).ready(function() {
setInterval("showNewTweets()", 1000);
});
function showNewTweets() {
$.getJSON("feed.php", null, function(data) {
if (data != null) {
$("#tweets").prepend($("<li><span class=\"author\">" + data.author + "</span> " + data.tweet + "<br /><span class=\"date\">" + data.date + "</span></li>").fadeIn("slow"));
}
});
}
</script>
</head>
<body>
<ul id="tweets"></ul>
</body>
</html>
PHP
<?php
echo json_encode(array( "author" => "someone",
"tweet" => "The time is: " . time(),
"date" => date('l jS \of F Y h:i:s A')));
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)