我有多个下拉菜单,每个下拉菜单都调用以下函数(传递不同的参数)如果我更改一个下拉菜单并等待响应一切都很好。如果我在第一个响应之前更改第二个下拉列表,则似乎从未调用过第一个回调。(虽然数据库中的数据已更改)
<script type="text/javascript">
<!--
function fg_insert_pick(element, team_id, tournament_id, pick_number) {
golfer_id = element.value;
golfer_name = element.options[element.selectedIndex].text;;
parent = element.parentNode;
parent.removeChild(element);
parent.innerHTML="submitting pick ...";
path = "'.plugins_url('fantasy-golf/submit/pick.php').'";
post = "team_id="+team_id+"&tournament_id="+tournament_id+"&pick_number="+pick_number+"&golfer_id="+golfer_id;
parent.innerHTML="submitting pick ...";
fg_ajax_request(path, post, function(response) {
if (response) {
parent.innerHTML=golfer_name;
} else {
parent.innerHTML="Something went wrong, please reload the page";
}
});
}
function fg_ajax_request(url, post, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange= function () {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
callback(xmlhttp.responseText);
}
}
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(post);
}
//-->
</script>