如何用ajax 返回两个值在不同DIV里

我在htm页使用 onclick="sent(2014,1); <div id=DIV1></div> <div id=DIV2></div>
JS使用
var xmlHttp;
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function get(tid,xid){
S_xmlhttprequest();
xmlHttp.open("GET","/url.php?vid="+tid+"&no="+xid,true);
xmlHttp.onreadystatechange=kankan;
xmlHttp.send(null);
}
function kankan(){
if(xmlHttp.readyState == 4)
{
var kk= xmlHttp.responseText;
document.getElementById("DIV1").innerHTML=kk;
}
}
以上这样是可以的,点击后返回一个值。
我现在想获得两个值,这样写是不是有问题啊?
var xmlHttp;
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function get(tid,xid){
S_xmlhttprequest();
xmlHttp.open("GET","/url.php?vid="+tid+"&no="+xid,true);
xmlHttp.onreadystatechange=kankan;
xmlHttp.send(null);

xmlHttp.open("GET","/url2.php?id="+xid,true);
xmlHttp.onreadystatechange=zaikan;
xmlHttp.send(null);

}
function kankan(){
if(xmlHttp.readyState == 4)
{
var kk= xmlHttp.responseText;
document.getElementById("DIV1").innerHTML=kk;
}
}

function zaikan(){
if(xmlHttp.readyState == 4)
{
var zk= xmlHttp.responseText;
document.getElementById("DIV2").innerHTML=zk;
}
}
请高手指点下,帮我改改,谢谢。

第1个回答  推荐于2016-04-04
function kankan(){
if(xmlHttp.readyState == 4)
{
var kk= xmlHttp.responseText;
//返回规定格式的字符串1,2
strs=kk.split(",");
document.getElementById("DIV1").innerHTML=strs[0];
document.getElementById("DIV2").innerHTML=strs[1];
}本回答被提问者采纳
相似回答