温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:Ajax实现无刷新添加和删除数据源码
当前文件路径:AjaxInsertDelete/js/xmlHttp.js

1//该源码下载自www.51aspx.com(51aspx.com) 2
3
function callback(){ 4
if(http_request.readyState==4){ 5
if(http_request.status==200){ 6
showmsg();//处理服务器返回的数据 7
} 8
} 9
} 10
//查询的请求 11
function userinforequest(){ 12
var url='Handler2.ashx'; 13
send_request("GET",url,null,"text",callback); 14
} 15
16
//添加信息 17
function submitrequest(){ 18
var name=escape(document.getElementById("txtname").value); 19
var pwd=escape(document.getElementById("txtpwd").value); 20
var url='Handler2.ashx?name='+name+'&pwd='+pwd; 21
send_request("GET",url,null,"text",callback); 22
} 23
//删除的请求 24
function deleterequest(id){ 25
var url='Handler2.ashx?delID='+id; 26
send_request("GET",url,null,"text",callback); 27
} 28
29
function showmsg(){ 30
// t1.innerText="";//清空表格 31
var xml=http_request.responseXML 32
if(xml==null)return; 33
var root=xml.documentElement;//得到xml文档对象 34
if(root) //如果存在 35
{ 36
//遍历每条数据,添加到频道数组中 37
var list=document.getElementById("mydiv"); 38
var s="<table border='1' cellpadding='0' cellspacing='0' bordercolor='#F7CEFF' style:'border-collapse:collapse align=center'><tr><TD bgColor='#FAF0FF' height='25'>ID号</td><TD bgColor='#FAF0FF' height='25'>姓名</td><TD bgColor='#FAF0FF' height='25'>小名</td><TD bgColor='#FAF0FF' height='25'>牛比删除我</td></tr>"; 39
for(var i=0;i<root.childNodes.length;i++)//遍历行 40
{ 41
var rootlist=root.childNodes[i]; 42
for(var j=0;j<rootlist.childNodes.length;j++)//遍历列 43
{ 44
var s1="<tr>"; 45
s1+="<TD bgColor='#FAF0FF' height='25'>"+rootlist.childNodes[0].text+"</TD>"; 46
s1+="<TD bgColor='#FAF0FF' height='25'>"+rootlist.childNodes[1].text+"</TD>"; 47
s1+="<TD bgColor='#FAF0FF' height='25'>"+rootlist.childNodes[2].text+"</TD>"; 48
s1+="<TD bgColor='#FAF0FF' height='25'><a href='' onclick='deleterequest("+rootlist.childNodes[0].text+")';>删除</a></TD>"; 49
} 50
s1+="</tr>"; 51
s+=s1; 52
list.innerHTML=s+"</table>"; 53
} 54
} 55
56
} 57
58
59
60
61





showmsg();
}