【发布时间】:2009-08-21 16:30:15
【问题描述】:
index.php 有这个 jquery 代码,它每 X 秒将 notification.inc.php 加载到页面上的一个 div 中
<script type='text/javascript'>
$(document).ready(function(){
var updatenotification = function(){
$('#notificationcontainer')
.load('notifications.inc.php')
.fadeIn("slow");
};
var auto_refresh = setInterval(function(){updatenotification();}, 5000);
updatenotification();
});
</script>
notifications.inc.php
<?PHP
if(notifications != 0){
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="box1r">
<tr><td height="25">Notifications</td></tr><tr><td colspan="2" bgcolor="#FFFFFF" height="11">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?PHP
if($item1 == 1){
echo 'AN HTML TEXT LINK HERE';
else if($item2 == 1){
echo 'AN HTML TEXT LINK HERE';
else if($item3 == 1){
echo 'AN HTML TEXT LINK HERE';
else if($item4 == 1){
echo 'AN HTML TEXT LINK HERE';
}
// ect. ect
?>
</table></td></tr></table>
<?PHP
}// end main block, only show the header "Notification" text if there is at least 1 notification ITEM to be shown
?>
现在这对我来说效果很好,可以显示用户何时收到新消息, cmets,照片 cmets,好友请求,主页上的类似内容。
我的网站流量很大,我想在各个方面改进代码,(请保存预优化是邪恶的言论,我只有时间,已经在这个网站上工作了 2 年,我想尽我所能)
所以我认为这可以做得更好吗?首先我知道我应该重新编码表格以使用 DIV,但现在我将在这个特定页面上使用这个表格设置。
那么为了节省带宽和性能,我应该使用 JSON 还是其他东西,而不是每 10 秒左右加载另一个页面的内容?
如果我应该使用 JSON 或其他东西,请稍微解释一下,我是 JS 新手,所以我不确定如何准确实现它
【问题讨论】:
标签: php javascript jquery xml json