jquery - Add and Return Value From Function With Json -
i have function uses ajax , json values table review. json works. gives value need. now, wanna add every value got inside tr
, td
, return it. gives '' or blank value. hope there solution :)
function get_review(id_jurnal){ var row= ''; var example = (function () { function self() { } self.request = function (params) { $.ajax({ data: "idjurnal_review="+id_jurnal, url: "php/ambildata.php", cache: false, async: true, success: function ($json) { params.success($json); } }); }; return self; })($); var locale = example.request({ async: true, // set false enable synchronized calls url: "php/ambildata.php", success: function ($json) { locale = $json; var response = eval("(" + $json + ")"); for(i=0;i < response.messages.pesan.length; i++) { id_review = response.messages.pesan[i].id_review; tglmulai_review = response.messages.pesan[i].tglmulai_review; tglselesai_review = response.messages.pesan[i].tglselesai_review; file_review = response.messages.pesan[i].file_review; var data = '<tr>'+ '<td width="20%">tgl penunjukan</td>'+ '<td width="1%">:</td>'+ '<td>'+tglmulai_review+'</td>'+ '</tr>'; row = row + data; } } }); return row; }; var id_jurnal = 1; get_review(id_jurnal); return '<table cellpadding="5" cellspacing="0" border="0" class="redshown">'+get_review(id_jurnal)+'</table>';
i got solution after refreshing brain :d do. firstly make table first.
function format ( d ) {
return '<table cellpadding="5" cellspacing="0" border="0" class="redshown"><tr id="tabelbaru"></tr></table>'; }
and after make function calling data ajax json
function get_review(id_jurnal){ var example = (function () { function self() { } self.request = function (params) { $.ajax({ data: "idjurnal_review="+id_jurnal, url: "php/ambildata.php", cache: false, async: true, success: function ($json) { params.success($json); } }); }; return self; })($); var locale = example.request({ async: true, // set false enable synchronized calls url: "php/ambildata.php", success: function ($json) { locale = $json; var response = eval("(" + $json + ")"); for(i=0;i < response.messages.pesan.length; i++) { id_review = response.messages.pesan[i].id_review; tglmulai_review = response.messages.pesan[i].tglmulai_review; tglselesai_review = response.messages.pesan[i].tglselesai_review; file_review = response.messages.pesan[i].file_review; idjurnal_review = response.messages.pesan[i].idjurnal_review; var row = $(document.createelement('tr')).attr("id", 'divtambah' + idjurnal_review); row = '<tr>'+ '<td width="20%">tgl penunjukan</td>'+ '<td width="1%">:</td>'+ '<td>'+tglmulai_review+'</td>'+ '</tr>'; $(row).insertbefore("#tabelbaru"); } } }); };
and use javascript insert tr , td. :)
Comments
Post a Comment