简单的Ajax代码
这段代码曾经让我激动了好久,收藏起来先,以后备用。
1
//根据输入的id在服务器查找返回name的函数
2
function GetName(id){
3
var xmlhttp = false;
4
/*@cc_on @*/
5
/*@if (@_jscript_version >= 5)
6
try{
7
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
8
}catch(e){
9
try{
10
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
11
}catch(e2){
12
xmlhttp = false;
13
};
14
};
15
@end @*/if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){xmlhttp = new XMLHttpRequest();};
16
if (xmlhttp) {
17
xmlhttp.onreadystatechange=function () {
18
if(xmlhttp.readyState==4) {
19
if(xmlhttp.status==200) {
20
show(unescape(xmlhttp.responseText));
21
}else {
22
/*alert("error");*/
23
}
24
}
25
}
26
xmlhttp.open("get","Ajax.aspx?id=" + id);
27
xmlhttp.send(null);
28
}
29
}
30![]()
31
//将获得的值输出到HTML控件中
32
function show(text) {
33
var obj;
34
obj = document.getElementById("Txt_ID");
35
obj.innerHTML = text;
36
}
//根据输入的id在服务器查找返回name的函数2
function GetName(id){3
var xmlhttp = false;4
/*@cc_on @*/5
/*@if (@_jscript_version >= 5)6
try{7
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");8
}catch(e){9
try{10
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");11
}catch(e2){12
xmlhttp = false;13
};14
};15
@end @*/if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){xmlhttp = new XMLHttpRequest();};16
if (xmlhttp) {17
xmlhttp.onreadystatechange=function () {18
if(xmlhttp.readyState==4) {19
if(xmlhttp.status==200) {20
show(unescape(xmlhttp.responseText));21
}else {22
/*alert("error");*/23
}24
}25
} 26
xmlhttp.open("get","Ajax.aspx?id=" + id);27
xmlhttp.send(null);28
} 29
}30

31
//将获得的值输出到HTML控件中32
function show(text) {33
var obj;34
obj = document.getElementById("Txt_ID");35
obj.innerHTML = text;36
}



浙公网安备 33010602011771号