JavaScript 简单理解Ajax异步调用操作的文章。
文章地址:http://www.soaspx.com/dotnet/ajax/javascript/javascript_20090915_349.html
这篇文章是理解Ajax技术的简单例程,挺简明扼要,很容易理解。
Ajax提供与服务器异步通信的能力,借助于Ajax,可以在用户单击按钮时,使用JavaScript和 DHTML立即更新UI,并向服务器发出异步请求,以执行更新或查询数据库。当请求返回时,就可以使用JavaScript和CSS来相应地更新UI,而不是刷新整个页面。最重要的是,用户甚至不知道浏览器正在与服务器通信:Web站点看起来是即时响应的。示例代码如下:
简单示例代码
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title > 无标题页 </ title >
< script type ="text/javascript">
var XmlHttp= new ActiveXObject("Microsoft.XMLhttp");
function sendRequest()
{
XmlHttp.Open("POST","http://www.cnblogs.com/abeen/rss", true ); // 请求数据页面
XmlHttp.send( null );
XmlHttp.onreadystatechange=ServerState; // 设置监听状态
}
// 请求到数据时显示到页面
function ServerState()
{
if (XmlHttp.readystate==4 || XmlHttp.readystate=='complete')
{
document.getElementById('contentList').innerHTML =XmlHttp.responsetext;
}
}
setInterval('sendRequest()',5000); // 设置更新时间
</ script >
</ head >
< body >
< div id ="contentList"></ div >
</ body >
</ html >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title > 无标题页 </ title >
< script type ="text/javascript">
var XmlHttp= new ActiveXObject("Microsoft.XMLhttp");
function sendRequest()
{
XmlHttp.Open("POST","http://www.cnblogs.com/abeen/rss", true ); // 请求数据页面
XmlHttp.send( null );
XmlHttp.onreadystatechange=ServerState; // 设置监听状态
}
// 请求到数据时显示到页面
function ServerState()
{
if (XmlHttp.readystate==4 || XmlHttp.readystate=='complete')
{
document.getElementById('contentList').innerHTML =XmlHttp.responsetext;
}
}
setInterval('sendRequest()',5000); // 设置更新时间
</ script >
</ head >
< body >
< div id ="contentList"></ div >
</ body >
</ html >