我有一個Web服務與鏈接:http://41.128.183.109:9090/api/data/getalllocations
如何在jQuery中從webservice獲取數據?
我使用jQuery。這個數據包含2個對象LocationName
和LocID
recived在下拉列表中該數據。我想在jQuery的下拉更改函數中顯示LocID
的提醒。這裏是我的代碼:
$(document).ready(function() {
$.ajax({
type: 'Get',
url: 'http://41.128.183.109:9090/api/data/getalllocations',
success: function (data) {
var SubDropdown = $("#main");
for (var i = 0; i < data.length; i++) {
SubDropdown.append('<option value?' + i + '?="">' + data[i].LocationName + '</option>');
}
}
});
});
$("#countries").change(function() {
alert();
});
這裏是我的HTML代碼:
<select tabindex="-1" class="select2_group form-control" style="display: normal; width: 290px;" name="countries" id="countries">
<optgroup label="Select Your City" id="main"></optgroup>
</select>
您需要更好地描述問題是什麼。 – Kivylius