其实基本使用都明白,就是没有想到,举一个例子吧。
<script ype="text/javascript">
var xmlHttp;
//创建一个XmlHttpRequeset对象

function createXMLHttpRequest()...{

if(window.ActiveXObject)...{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

else if(window.XMLHttpRequest)...{
xmlHttp = new XMLHttpRequest();
}
}
//开始一个请求

function startRequest()...{
createXMLHttpRequest();
xmlHttp.onreadystatechange = handlestatechange;
xmlHttp.open("GET", "innerHtml.xml", true);
xmlHttp.Send(null);
}

function handlestatechange()...{

if(xmlHttp.readyState == 4)...{//描述一种"已加载"状态;此时,响应已经被完全接收。

if(xmlHttp.status == 200)...{//200表示成功收到
document.getElementById("results").innerHTML = xmlHttp.ResponseText;
}
}
}
</script>
把innerHtml.xml换成aaa.aspx,然后把aaa.aspx里的html全部清空。只在aaa.aspx.cs的Page_Load函数里面写上想要的数据,然后就可以了。如下
protected void Page_Load(object sender, EventArgs e)

...{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();

string custID = Request.QueryString["CustID"].ToString().Trim();
//string custID = "11532";
string assetIDs = GetAssetIDsByCustID(custID);
Response.Write(assetIDs);

Response.End();
<script ype="text/javascript">
var xmlHttp;
//创建一个XmlHttpRequeset对象
function createXMLHttpRequest()...{
if(window.ActiveXObject)...{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)...{
xmlHttp = new XMLHttpRequest();
}
}
//开始一个请求
function startRequest()...{
createXMLHttpRequest();
xmlHttp.onreadystatechange = handlestatechange;
xmlHttp.open("GET", "innerHtml.xml", true);
xmlHttp.Send(null);
}
function handlestatechange()...{
if(xmlHttp.readyState == 4)...{//描述一种"已加载"状态;此时,响应已经被完全接收。
if(xmlHttp.status == 200)...{//200表示成功收到
document.getElementById("results").innerHTML = xmlHttp.ResponseText;
}
}
}
</script>
把innerHtml.xml换成aaa.aspx,然后把aaa.aspx里的html全部清空。只在aaa.aspx.cs的Page_Load函数里面写上想要的数据,然后就可以了。如下
protected void Page_Load(object sender, EventArgs e)
...{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
string custID = Request.QueryString["CustID"].ToString().Trim();
//string custID = "11532";
string assetIDs = GetAssetIDsByCustID(custID);
Response.Write(assetIDs);
Response.End();
本文介绍了一种通过Ajax实现页面局部刷新的方法,具体演示了如何使用JavaScript创建XmlHttpRequest对象,并发送GET请求到服务器端获取数据,再将这些数据动态地显示在网页中。
4911

被折叠的 条评论
为什么被折叠?



