gpt4 book ai didi

javascript - 在 onchange 事件上调用 2 个 ajax 函数

转载 作者:行者123 更新时间:2023-11-30 18:40:49 26 4
gpt4 key购买 nike

我希望在下拉菜单的 onchange 事件中同时调用 3 个 ajax 函数。

我尝试调用第一个函数的 if (xmlhttp1.readyState==4 && xmlhttp1.status==200) 中的第二个函数和 if (xmlhttp1.readyState) 中的第三个函数==4 && xmlhttp1.status==200) 第二个函数。

但是只调用了第一个函数,连第二个函数都没有调用。还有其他方法可以实现吗?

函数如下:

function list1(ob){

var id= ob;
var xmlhttp1;

if (window.XMLHttpRequest){//for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp1=new XMLHttpRequest();
}else{//for IE6, IE5
xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp1.onreadystatechange = function(){
if (xmlhttp1.readyState==4 && xmlhttp1.status==200){
alert("ajax1");
list2(id);
}
}

xmlhttp1.open("POST","/ajax/listSites.php",true);
xmlhttp1.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
xmlhttp1.send("id="+id);
}


function list2(obb){

var idd=obb;
var xmlhttp;

if (window.XMLHttpRequest){// for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
alert("ajax2");
list3(idd);
}
}

xmlhttp.open("POST","/ajax/access_points_do_actions.php",true);
xmlhttp.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
xmlhttp.
send("sel_system_id="+idd+
"&action="+'LIST_SLAVE_FOR_ACCESS_POINT');

}

// only alert ajax1 is displayed

最佳答案

您可以像这样链接异步调用:

onchange="Function1(); Function2();"

更新:

您的代码:

<select id="se" onchange="javascript:list1(this.value); //this is current code

应该是这样的:

<select id="se" onchange="Javascript: list1(this); list1(this);">

关于javascript - 在 onchange 事件上调用 2 个 ajax 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6914708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com