AJAX无刷新更新数据
2006-10-03 10:06
381 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<script language="JavaScript">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function GetResult()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**//**//*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*--------------- GetResult() -----------------
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* GetResult()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 功能:通过XMLHTTP发送请求,返回结果.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 参数:str,字符串,发送条件.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 实例:GetResult();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*--------------- GetResult() -----------------
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var oBao = new ActiveXObject("Microsoft.XMLHTTP");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//特殊字符:+,%,&,=,?等的传输解决办法.字符串先用escape编码的.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//Update:2004-6-1 12:22
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oBao.open("POST","foo.php",false);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oBao.send();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//服务器端处理返回的是经过escape编码的字符串.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var strResult = unescape(oBao.responseText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//将字符串分开.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var arrResult = strResult.split("###");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RemoveRow(); //删除以前的数据.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//将取得的字符串分开,并写入表格中.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(var i=0;i<arrResult.length;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/In<br/>4000<br/>Block.gif)
arrTmp = arrResult[i].split("@@@");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
num1 = arrTmp[0]; //字段num1的值
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
num2 = arrTmp[1]; //字段num2的值
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
row1 = tb.insertRow();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cell1 = row1.insertCell();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cell1.innerText = num1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cell2 = row1.insertCell();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cell2.innerText = num2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function RemoveRow()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//保留第一行表头,其余数据均删除.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var iRows = tb.rows.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(var i=0;i<iRows-1;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
tb.deleteRow(1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function MyShow()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//2秒自动刷新一次,2秒取得一次数据.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
timer = window.setInterval("GetResult()",2000);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body onload="MyShow()">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<p>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</p>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table width="47%" height="23"border="0" cellpadding="1" cellspacing="0" id="tb">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td>num1</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td>num2</td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
相关文章推荐
- ajax异步问题导致的刷新页面数据不更新
- 关于ajax局部刷新,从数据库实时更新数据到页面(一般是下订单成功后发送消息到后台)
- Ajax无刷新的获取数据绑定GridView及无刷新更新数据
- Ajax异步无刷新对局部数据更新
- .NET 使用 Ajax 无刷新更新数据
- ajax页面无刷新 IE下遭遇Ajax缓存导致数据不更新的问题
- 通过Ajax技术实现无刷新的更新数据表格
- Ajax异步无刷新更新局部数据
- Ajax实现无刷新的获取数据并绑定到GridView,以及无刷新更新数据[转]
- ajax页面无刷新 IE下遭遇Ajax缓存导致数据不更新的问题
- 页面无刷新更新数据(ajax异步加载)
- 1.MVC框架复习 2.Ajax加强 3.搜索建议 4,三级联动 5、刷新分页 6、Ajax局部动态更新数据
- ajax页面无刷新 IE下遭遇Ajax缓存导致数据不更新的问题
- 1.MVC框架复习 2.Ajax加强 3.搜索建议 4,三级联动 5、刷新分页 6、Ajax局部动态更新数据
- ASP.NET MVC2 利用AJAX 无刷新实时更新数据
- ajax 无刷新定时更新数据
- 使用 jQuery+Ajax+MySQL+Servlet 实现不刷新页面数据更新
- Ajax跨域的解决办法:载入javascript(js)文件实现无刷新更新数据(转载)
- ajax异步刷新实现更新数据库