I have mechanism that use AJAX to send-receive data. The data is sent to a php file then when complete the result will be sent back in JSON-from (use encode_json method). Then the json data that received will be extracted for each aim.
The problem appear, when I try to extract the json message that transfered from php file. This is the Javascript part
function set_filter() {
var a = document.getElementById('Tema');
var b = a.options[a.options.selectedIndex].value;
$.get("filter.php", {tema: b, method: 'set_filter'}, function(data, status) {
alert(status);
console.log(data);
x = JSON.parse(data);
alert(x.count);
});
}
This How result of console.log(data)
Blockquote {"filters":{"id_filter":["2","1","3"],"judul_filter":["Jenis Arus Dana","Instansi NAD","Kategori Transaksi NAD"]},"select_list":[[["s","p"],["Sumber","Pengeluaran"]],[["1","2","3","4","5","6"],["Bank Sentral","Perbankan","Pemerintah","Domestik Lain","Luar Negeri","Seluruh Instansi"]],[["0200","0300","0400","0500","0600","0700","0800","0900","1000","1010","1020","1021","1022","1023","1024","1025","1030","1100","1200","1210","1220","1230","1300","1400","1410","1420","1500","1800","2000","9000","0100"],["Investasi Non Finansial","Pinjaman Neto","Selisih Statistik","Investasi Finansial Neto","Jumlah Penggunaan Finansial","Jumlah Sumber Finansial","Cadangan Valas Pemerintah","Klaim Dalam Valas Lainnya","Uang Dan Simpanan","Uang Dan Simpanan Dalam Valas","Uang Dan Simpanan Dalam Rupiah","Uang Kertas Dan Logam","Giro","Tabungan","Deposito Berjangka","Simpanan Rupiah Lainnya","Tabungan Giro Pos Dan Koperasi","Surat Berharga Jangka Pendek","Kredit","Kredit Bank Dalam Rupiah","Kredit Institusi Lain D.Rupiah","Kredit Dalam Valas","Modal Saham Dan Penyertaan","Surat Berharga Jangka Panjang","Surat Berharga Pemerintah","Surat Berharga Lainnya","Cadangan Asuransi Dan Pensiun","Kredit Dagang","Rekening Antar Bank","Rupa-Rupa","Tabungan Bruto"]]]}
And when I check this line "alert(x.count);", it's return
Undefined
If I want to extract all judul_filter or id_filter or other, How I can achieve each/specific element ?
NB: I've visit some link such as Cant read JSON produced by PHP into my javascript Parse JSON in JavaScript? Convert JSON string to Javascript array But from suggestion I try, it returns undefined or [pbject object]. Must the data parse to string using JSON.Stringify(data)? Or How?
-Thanks-