Javascript 选择多个选项,将它们用作数组,并在不加载页面的情况下从数据库检索数据
我无法在不加载页面的情况下从数据库检索多个select数据 我想选择多个选项并根据选择检索数据,以下是我的选择标记的代码:Javascript 选择多个选项,将它们用作数组,并在不加载页面的情况下从数据库检索数据,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我无法在不加载页面的情况下从数据库检索多个select数据 我想选择多个选项并根据选择检索数据,以下是我的选择标记的代码: <select name="country[]" multiple="multiple" onChange="getSkill(this.value)"> <option value="">--Select Categoery--</option> <?php while ($row=mysql_fetch_ar
<select name="country[]" multiple="multiple" onChange="getSkill(this.value)">
<option value="">--Select Categoery--</option>
<?php while ($row=mysql_fetch_array($result)) {
$cid = $row['cid'];
?>
<option value=<?php echo $row['cid']?>><?php echo $row['categotie']?></option>
<?php } ?>
</select>
我的AJAX代码是:
function getSkill(cid) {
var strURL="findskill.php?cid="+cid;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('skilldiv').innerHTML=req.responseText;
} else {
alert("Problem while using XMLHTTP:\n" + req.statusText);
document.getElementById('marksdiv').innerHTML='<p name="marks">'+
'</p>';
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
如何检索多个值?我只能检索一个值。根据您对服务器的期望,在处理多个选择时,必须正确获取值,而不是:
<select name="country[]" multiple="multiple" onChange="getSkill(this.value)">
与:
为什么您不能选择多个数据,您不能在页面中选择,或者您不能在服务器中选择?@juanpastas All我无法同时选择这两个iam真正需要的是这里cid有一个类似于1,2,3,4的saparate值,请检查并比较sel.val和$sel.val的值
<select name="country[]" multiple="multiple" onChange="getSkill($(this).val())">
var strURL="findskill.php?cid="+cid;
var strURL = "findskill.php?cid=" + cid.join(',');