ajax异步查询demo,ASP.NET中AJAX的异步加载(Demo演示)
此次的demo是一個頁面,頁面上有兩行字,然后后面用ajax,使用一個下拉框去替換第一行文字[/code]
第一個是被替換的網頁
var xmlhttprequest;
function createxmlhttprequest() {
if (window.activexobject) {
xmlhttprequest = new activexobject("microsoft.xmlhttp");//ie瀏覽器
} else {
xmlhttprequest = new window.xmlhttprequest();//谷歌等瀏覽器
}
}
function sendrequest() {
createxmlhttprequest();//獲取對象
xmlhttprequest.onreadystatechange = function () {
if (xmlhttprequest.readystate == 4) {
if (xmlhttprequest.status == 200) {
document.getelementbyid("divcontent").innerhtml = xmlhttprequest.responsetext;
}
}
};
xmlhttprequest.open("post", "depthandler.ashx", true);
xmlhttprequest.send(null);
}
這里顯示部門信息
這里顯示部門信息結束了
第二個是一個類
using system;
using system.collections.generic;
using system.linq;
using system.web;
namespace webapplication2
{
public class dept
{
public int id { get; set; }
public string deptname { get; set; }
}
}
然后是一個一般處理程序
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading;
using system.web;
namespace webapplication2
{
///
/// depthandler 的摘要說明
///
public class depthandler : ihttphandler
{
public void processrequest(httpcontext context)
{
//這里的ajax進行了三秒的延遲
thread.sleep(3000);
list depts = new list
{
new dept(){id=1,deptname="財務部"},
new dept(){id=2,deptname="研發部"},
new dept(){id=3,deptname="市場部"}
};
stringbuilder sb = new stringbuilder();
sb.appendline("");
foreach (var item in depts)
{
sb.appendline($"{item.deptname}");
}
sb.appendline("");
context.response.contenttype = "text/plain";
context.response.write(sb);
}
public bool isreusable
{
get
{
return false;
}
}
}
}
效果圖
ajax有三秒的延遲加載
前三秒
后三秒
到此這篇關于asp.net中ajax的異步加載(demo演示)的文章就介紹到這了,更多相關asp.net中ajax異步加載內容請搜索萬仟網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持萬仟網!
總結
以上是生活随笔為你收集整理的ajax异步查询demo,ASP.NET中AJAX的异步加载(Demo演示)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我眼中的软件测试,交互设计师眼中的软件测
- 下一篇: ajax 更新页面变量,[Django