次のコードを使用して、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モバイルリストボックスを使用していますが、3つの別々のリストボックスに表示することになっていますが、1つのリストボックスにのみ値を入力しています。
<ul data-role="listview">
<li>
</li>
</ul>
コードで行っている間違いはありますか?