2016-03-19 6 views
1

マイコードイグナイターmysqlJSON応答内容の一括メールアドレス。各メールアドレスにどのようにdivタグを追加する必要がありますか?最後の電子メールアドレスのみを表示するようになりました。Ajaxの各関数を動的なDIVタグ数で使用する方法

$(document).ready(function() { 
 
    $('#option1').click(function() { 
 
    $.ajax({ 
 
     url: '<?php echo base_url(); ?>' + 'main/studentdetails', 
 
     dataType: "JSON", 
 
     type: "POST", 
 
     success: function(retdata) { 
 
     $.each(retdata, function(i, item) { //i = number of records 
 
      $(".target").html(retdata[i].email); 
 
     }); 
 
     } 
 
    }); 
 
    }); 
 
});
<body> 
 
    <input type="button" id="option1"> 
 
    <div class='target'> 
 
    </div> 
 
</body>

+1

'$("。target ")。append(item.email);' –

答えて

2

あなたはそれ以外の場合は、以前の値に置き換えられますし、最後の値が表示され、代わりにhtml()append()を使用する必要があります。

$(".target").append(item.email); 
関連する問題