jQuery AJAX 呼び出しを介して PHP スクリプトから返された 2 次元の JSON 配列があります。各行をループしてdiv内に各エントリを表示する方法を見つけようとしてブラウジングしてきましたが、この特定のケースでそれを行う方法が非常に混乱していてわかりません。
サーバーから返される JSON の例を次に示します。
{"location_id":"505","location_name":"University of the Arts London","location_type":"uni","location_num_listings":"22","location_num_users":"187","relevancy":"2"},
{"location_id":"592","location_name":"London South Bank University","location_type":"uni","location_num_listings":"1","location_num_users":"1","relevancy":"2"},
{"location_id":"591","location_name":"London Metropolitan University","location_type":"uni","location_num_listings":"47","location_num_users":"185","relevancy":"2"},
{"location_id":"590","location_name":"University College London","location_type":"uni","location_num_listings":"29","location_num_users":"176","relevancy":"2"},
{"location_id":"586","location_name":"St George's, University of London","location_type":"uni","location_num_listings":"9","location_num_users":"4","relevancy":"2"},
これまでの私のスクリプトは次のとおりです。
<script type="text/javascript">
$("#directory_search_input").keyup(function() {
$("#directory_search_results").html('');
var regionvalue = $(this).val();
var jsonresult;
var url = '<?php echo site_url('ajax/ajax_default/directory_search')?>';
$.post(url,{input_val:regionvalue}, function(data) {
var results = jQuery.parseJSON(data);
$.each(results, function() {
$.each(this, function(index, value) {
$("#directory_search_results").append(/*Append a new div for each row returned*/);
});
}); });
望ましい出力の例:
ロケーション ID: 505、ロケーション名: ロンドン芸術大学
ロケーション ID: 592、ロケーション名: ロンドン サウス バンク大学
などなど