function gel(id) {
return document.getElementById(id);
}
function createXmlHttp() {//创建xhr对象
var xhobj = false;
try {
xhobj = new ActiveXObject("Msxml2.XMLHTTP"); // ie msxml3.0+
} catch (e) {
try {
xhobj = new ActiveXObject("Microsoft.XMLHTTP"); //ie msxml2.6
} catch (e2) {
xhobj = false;
}
}
if (!xhobj && typeof XMLHttpRequest != 'undefined') {// Firefox, Opera 8.0+, Safari
xhobj = new XMLHttpRequest();
}
return xhobj;
}
var xhr = false;
window.onload = function () {
xhr = createXmlHttp();
}
function doDel(id) {
xhr.open("POST", "Del.ashx", true);//AJAX异步操作
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");//表单方式
xhr.onreadystatechange = watching;
xhr.send("aid=" + id);//值
}
function doModify(id) {
window.location.href = "Modify.aspx?id=" + id;//修改
}
function watching() {
if (xhr.readystate == 4) {
if (xhr.status == 200){
var txt = xhr.responseText;
var txtArray = txt.split(",");//ok,2 返回过来的是(ok,2)
alert(txt);
if (txtArray[0] == "ok") {
var tbRows = gel("tbList").rows; //得到整个表格的行集合
for (i = 0; i < tbRows.length; i++) {
if (tbRows[i].childNodes[1].innerHTML == txtArray[1]) {
gel("tbList").deleteRow(i); //删除id相同的行
break;
}
}
} else {
alert("删除失败");
}
}
}
}
上面为用AJAX实现删除数据更新页面内容。AJAX 实现删除效果(同时更新页面值)
最新推荐文章于 2022-10-15 02:17:08 发布