多个Ajax值调用同一个页面的不同Action合并 - Web 开发 / Ajax
function get_a(){
$("a").innerHTML = '<p class="tC"><br/><br/><br/><br/><br/> <img src="loading.gif" /></p>';
createXMLHttpRequest();
XMLHttpReq.open("GET", "ceshi.asp?action=get_a",true);
XMLHttpReq.onreadystatechange= function(){
if(XMLHttpReq.readyState == 4){
if(XMLHttpReq.status == 200){
document.getElementById("a").innerHTML = unescape(XMLHttpReq.responseText);
document.getElementById("list_do").innerHTML = '<a href="#none" onclick="javascript:get_a();">刷新列表</a>';
} else {
document.getElementById("a").innerHTML = "加载失败!";
}
}
}
XMLHttpReq.send(null);
}
function get_b(){
$("b").innerHTML = '<p class="tC"><br/><br/><br/><br/><br/> <img src="loading.gif" /></p>';
createXMLHttpRequest();
XMLHttpReq.open("GET", "ceshi.asp?action=get_b",true);
XMLHttpReq.onreadystatechange= function(){
if(XMLHttpReq.readyState == 4){
if(XMLHttpReq.status == 200){
document.getElementById("b").innerHTML = unescape(XMLHttpReq.responseText);
document.getElementById("list_do").innerHTML = '<a href="#none" onclick="javascript:get_b();">刷新列表</a>';
} else {
document.getElementById("b").innerHTML = "加载失败!";
}
}
}
XMLHttpReq.send(null);
}
function get_c(){
$("c").innerHTML = '<p class="tC"> <img src="loading.gif" /></p>';
createXMLHttpRequest();
XMLHttpReq.open("GET", "ceshi.asp?action=get_c",true);
XMLHttpReq.onreadystatechange= function(){
if(XMLHttpReq.readyState == 4){
if(XMLHttpReq.status == 200){
document.getElementById("c").innerHTML = unescape(XMLHttpReq.responseText);
document.getElementById("list_do").innerHTML = '<a href="#none" onclick="javascript:get_c();">刷新列表</a>';
} else {
document.getElementById("c").innerHTML = "加载失败!";
}
}
}
XMLHttpReq.send(null);
}
function get_d(){
$("d").innerHTML = '<p class="tC"> <img src="loading.gif" /></p>';
createXMLHttpRequest();
XMLHttpReq.open("GET", "ceshi.asp?action=get_d",true);
XMLHttpReq.onreadystatechange= function(){
if(XMLHttpReq.readyState == 4){
if(XMLHttpReq.status == 200){
document.getElementById("d").innerHTML = unescape(XMLHttpReq.responseText);
document.getElementById("list_do").innerHTML = '<a href="#none" onclick="javascript:get_d();">刷新列表</a>';
} else {
document.getElementById("d").innerHTML = "加载失败!";
}
}
}
XMLHttpReq.send(null);
}
请问上面的a、b、c、d可以做个判断吗?如何做 请指教。
就只调用一个function get_a(这里是参数值) 主要是想减少代码!
------解决方案--------------------
JScript code
var cur;
function getIt(n){
cur = n;
$(n).innerHTML = '<p class="tC"> <img src="loading.gif" /></p>';
createXMLHttpRequest();
XMLHttpReq.