无刷新网页——数据岛技术应用

有些时候,只是需要更新页面的一个部分甚至只是更新中间的几个数据却需要从服务器DOWN整个页面,导致各种资源的浪费。

使用数据岛技术可以很好的解决这个问题:

通过定时器或用户事件触发数据岛(XML对象)象服务器获取数据,在数据获取完成后,适时更新相关数据。

示例
HTML部分:
<xml id=xmlData src="http://localhost/WebService/LoadData/FeaturedService.asmx/GetScores"></xml>

<div id=divDataList>
<table datasrc=#xmlData width="500"  border="0" width="70%"   cellspacing="1" cellpadding="1" showalign="left" style="line-height: 140%">
<thead>
<tr bgcolor="#0033CC" style="color: #ffffff">
<td width="13%" nowrap>赛事名</td>
<td width="3%" nowrap>對賽隊伍</td>
<td width="25%">比分</td>
<td width="10%" nowrap>對賽隊伍</td>
<td width="25%">半場</td>
<td width="13%" nowrap>比赛状态</td>
</tr>
</thead>
<tbody>
<tr bgcolor="#0033CC" style="color: #ffffff">
<td width="13%" nowrap><span datafld=MatchName></span></td>
<td width="13%" nowrap><span datafld=MatchTime></span></td>
<td width="11%"  nowrap><span datafld=HostTeam></span></td>
<td width="3%" nowrap><span datafld=MatchScore></span></td>
<td width="25%"><span datafld=CustomerTeam></span></td>
<td width="10%" nowrap><span datafld=HalfScore></span></td>
<td width="25%"><span datafld=MatchState></span></td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
</div>
<div id=divWaitMsg>
请稍候,正在更新数据
</div>
<script language=javascript>
function ShowDataList()
{
divDataList.style.display="";
divWaitMsg.style.display="none";
setTimeout(GetNewData,10000);
}
function GetNewData()
{
divDataList.style.display="none";
divWaitMsg.style.display="";
xmlData.src=xmlData.src;
}
</script>

WebService 部分:
[WebMethod]
  public string GetScores()
  {
   string connectionString="Server=Root;database=kakai;User id=sa;password=201080";
   SqlConnection conn;
   conn=new SqlConnection(connectionString);
   string SQL;
   SqlDataAdapter Adpt;
   DataSet ds;
   SQL="Select MatchName,MatchTime, HostTeam,CustomerTeam,MatchScore,HalfScore,MatchState From ShowScores where MatchDate='11月8日'";
   Adpt=new SqlDataAdapter(SQL,conn);
   ds=new DataSet();
   Adpt.Fill(ds,"ShowScores");
return ds.Getxml();
}


具体,请参考网站:
http://www.newart2.com/SucCase.Asp
本页面的成功案例的分页、分类导航即使用数据岛技术实现。

posted @ 2004-05-06 00:15  无之无  阅读(7932)  评论(17编辑  收藏  举报