Reputation: 441
I have a script that post a variable and get a JSON as result. This is the script:
$.post('<?php echo site_url('Admin/get_memo_by_surat'); ?>',{data:id},function(result){
alert(result);
});
When I do alert if the script success post the variable, I get this JSON :
[{"no_dokumen":"19\/0001-1\/SCG","dari":"PPC","pic":"77973035","kepada":"PPC","instruksi":"Mas Dwi tolong hps","tanggal_dist":"2017-03-27 13:31:53","tanggal_proses":"0000-00-00 00:00:00"},{"no_dokumen":"19\/0002-1\/SCG","dari":"PPC","pic":"77973035","kepada":"PMD","instruksi":"Test to PMD","tanggal_dist":"2017-03-27 13:32:15","tanggal_proses":"0000-00-00 00:00:00"}]
I've tried using $.each
, but it show nothing.
$.each(result, function(i,response){ alert(response.no_dokumen); });
So, how do I loop through this? I'd like to represent this data in a table by the way.
Upvotes: 0
Views: 100
Reputation: 146
this result variable contain json data but string. you just add the new line:
var data = JSON.parse(result);
and then try,
$.each(data, function(i, response){ alert(response.no_dokumen); });
Upvotes: 1