我的ajax函数是这样的我在响应中获取数据,但无法在选择框中设置响应数据:
display: inline;
我的HTML是这样的:
display: inline-block;
答案 0 :(得分:1)
假设您的回复是option
HTML。
您应该将数据附加到select
:
var myarray;
function getmember() {
myarray = [];
myarray.push($(".group_id").val());
$.ajax({
type: "POST",
url: "getmember.php",
data: 'group_id=' + myarray.join(),
success: function(data) {
$('#mySelect').append('<option value="' + data + '">'+ data + '</option>');
// ^^^^^^
}
});
return false;
}
HTML:
<select id="mySelect">
<option>Select User</option>
<div class="groop"></div>
</select>
答案 1 :(得分:0)
JQuery:
<head>
<script type="text/javascript">
var myarray;
function getmember() {
myarray = [];
myarray.push($(".group_id").val());
$.ajax({
type: "POST",
url: "getmember.php",
data: 'group_id=' + myarray.join(),
success: function(data) {
$('.groop').append(data);
$(".groop").html('');
for (var i = 0; i < data.length; i++) {
$(".groop").append('<option value=' + data[i].YourId + '>' + data[i].YourText + '</option>');
}
}
});
return false;
}
</script>
</head>
HTML:
<select id="ddlYourName" class="groop" onchange="getmember()"></select>