ここですべてのユーザーの名前を取得し、ID をその名前として設定します。ここでは、画像の ID を名前として設定します。次に、それらの画像をクリックすると、その名前のデータを使用して表示される history.php ページに名前を渡します。しかし今、window.location の行項目は未定義です。これは正しい方法ですか、それとも他の標準的な方法はありますか?
$.getJSON('rest.php/names', function(data) {
var items = [];
var recs = data.records;
for(var i=0; i<recs.length; i++){
items[i] = recs[i].name;
$('#theImg').append('<img id="' + items[i] + '"' + 'src="images/Arrow-Left.png" />');
$("img").click(function(){
window.location = 'history3.php?name=' + items[i];
});
}
});