Ajax 回调函数callback的重用问题
当我想重用callback的时候出现问题了
还是依然反馈回来的是第一个绑定的callback
麻烦帮小弟看一下 十分感谢啦
代码如下:
function doclick() {
var url = "validate2.do?id=" + test + "&id2=" + test2;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, true);
req.onreadystatechange = function () { callback('doclick1'); }
req.send(null);
}
function callback(p) {
if (req.readyState == 4 && req.status == 200) {
var check = req.responseText; //查看接收到的后台传过来的html命令
alert("看看接收到的p是多少"+p);
//此句最后无论怎么 接收到的永远是doclick 而接收不到doclick2
show(check,p);
};
}
function show(str,p) {
//////
if (p == 'doclick') {
var show = str;
document.getElementById("status1").innerHTML = show;
if (str == "Disconnect") {
var show = "<img src=\"images/failed.gif\" height=\"16\" width=\"16\"> <font color='red'> Sorry, Disconnect! Please reconnect.</font>";
document.getElementById("status1").innerHTML = show;
} else if (str == "TIMEOUT") {
var show = "<img src=\"images/failed.gif\" height=\"16\" width=\"16\"> <font color='red'> Sorry, Connection time out!</font>";
document.getElementById("info").innerHTML = show;
}
doclick(); //收到数据后继续执行doclick事件继续监听后台
}
else if (p&nbs