几个小时以来,我一直在为将Json数据放入选择框而苦苦挣扎,现在我可以在Ajax中成功地检索我的json数据了。
问题是ID在选择框中显示为带有名称的选项,我不希望只显示名称而隐藏Id值。
到目前为止,我拥有的代码..
<select id="seasontype_select">
<option value=""> select</option>
</select>
Json数据:
[{"value":"1","label":"BrushPickup"},{"value":"2","label":"LeafPickup"}]
Ajax:
$.ajax({
url: 'SelectType.ashx',
method: 'POST',
dataType: 'json', //make sure your service is actually returning json here
contentType: 'application/json',
data: '{}',
success: function (data, status) {
//Here Is Where I get the Value: ID, with Label don't want that just Label should show
$.each(data, function (i, d) {
$('#seasontype_select').append('<option value"' + i + '">' + d + '</option>');
});
}
});
});
发布于 2018-07-25 04:14:00
我自己就能解决这个问题,我想通了!除了使用
$.ajax({
url: 'SelectType.ashx',
method: 'POST',
dataType: 'json', //make sure your service is actually returning json here
contentType: 'application/json',
data: '{}',
success: function (data, status) {
$.each(data, function (i,d) {
$('#seasontype_select').append('<option value"' + d.value + '">' + d.label + '</option>');
});
}
});
});
https://stackoverflow.com/questions/51506614
复制相似问题