2
我一直在嘗試使用提供的JSON來使用select2填充我的輸入。 這裏的JSON:Select2與JSON的AJAX
{
"airports":
[
{
"id": "1",
"code": "AMQ",
"city": "Ambon",
"country": "Indonesia"
},
{
"id": "2",
"code": "BJW",
"city": "Bajawa",
"country": "Indonesia"
}
]
}
和HTML代碼:
<input class="" type='hidden' value="192" data-init-text='Departing City' name='input' id='depart-airport' style="width: 300px"/>
而且JS代碼:
$(document).ready(function() {
$('#depart-airport').select2({
minimumInputLength: 1,
ajax: {
url: "http://localhost:4000/api/airports.json",
dataType: 'json',
results: function (data) {
return { results: data};
}
}
});
});
有控制檯沒有錯誤,但我是否嘗試輸入他們這是總是說「搜索失敗」或者什麼都沒有。 json的數據從未顯示過。 你有什麼可以解決這個問題嗎?感謝的:)
您是否嘗試過調試與谷歌Chrome「網絡」標籤?或者你可以粘貼你的服務器的代碼?我們需要更多信息來幫助你。 –
看到這個希望它有幫助:http://jsfiddle.net/LUsMb/3538/ –