我從JSON使用jQuery使用此代碼獲取值:在出發從JSON
$(document).ready(function() {
$.ajax({
type : 'GET',
url : 'outfitters.json',
dataType : 'json',
success : processTeam,
error : function() {
alert('error');
}
});
});
function processTeam(data) {
var company = data.company;
$("h1").html(company);
var locations;
for (i = 0; i < data.locations.length; i++) {
locations += data.locations[i].name + "<br/>";
}
$("li").html(locations);
}
事實上,我得到預期的輸出,但有一個額外的「不確定」輸出是這樣的:
undefinedKincardine
Killarney
Bon Echo
此外,我使用jQuery Mobile的列表框中,但儘管它是爲了顯示它在三個不同的人其只在一個列表框填充值。
<ul data-role="listview">
<li>
</li>
</ul>
我在我的代碼中做的任何錯誤?
是什麼'data.locations'看起來像? – Blender 2013-03-06 04:51:47