var doc;
window.onload = function()
{
if(window.ActiveXObject)
{
doc = new ActiveXObject("Microsoft.XMLHttp");
}
else if(window.XMLHttpRequest)
{
doc = new XMLHttpRequest();
}
}
function test()
{
doc.open("Get","/Ajax/test.aspx",false);
doc.onreadystatechange = function()
{
if(doc.readystate == 4)
{
if(doc.status == 200)
{
document.getElementById("ddd").innerHTML = doc.responseText;
}
else
{
document.getElementById("ddd").innerTHML = "服务器返回状态:"+doc.statusText;
}
}
else
{
document.getElementById("ddd").innerHTML = "请等待.";
}
}
doc.send(null);
}
window.onload = function()
{
if(window.ActiveXObject)
{
doc = new ActiveXObject("Microsoft.XMLHttp");
}
else if(window.XMLHttpRequest)
{
doc = new XMLHttpRequest();
}
}
function test()
{
doc.open("Get","/Ajax/test.aspx",false);
doc.onreadystatechange = function()
{
if(doc.readystate == 4)
{
if(doc.status == 200)
{
document.getElementById("ddd").innerHTML = doc.responseText;
}
else
{
document.getElementById("ddd").innerTHML = "服务器返回状态:"+doc.statusText;
}
}
else
{
document.getElementById("ddd").innerHTML = "请等待.";
}
}
doc.send(null);
}
aspx文件
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("输出内容!");
}
{
Response.Write("输出内容!");
}
另:实现调用一个aspx文件多个方法:
调用时:
doc.open("Get","/Ajax/test.aspx?id=1",false);
加个参数
doc.open("Get","/Ajax/test.aspx?id=1",false);
加个参数
aspx文件代码:
protected void Page_Load(object sender, EventArgs e)
{
string id = Request["id"];
if(id==1)
Response.Write("结果1");
else if(id==2)
Response.Write("结果2");
}
{
string id = Request["id"];
if(id==1)
Response.Write("结果1");
else if(id==2)
Response.Write("结果2");
}
不过很遗憾,我所知道的基于xmlhttprequest的ajax不能支持firefox,找了很多资料也是,但可以借助ajaxPro,更好的办法是用jQuery库,它也是基于httprequest的,但还不知道它是怎么实现的。