javascript - how to create multiple json arrays and pass all arrays in the same function -
i new json , stuck @ simple syntax not able figure out
i have json:
{"full_talktime":[ {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"} ]}
and function:
$(function() { $.getjson('data.json', function(data) { $.each(data.full_talktime, function(index, plan) { var tblpara = $('<p class="col1">').html("<b>talktime</b><br>"); var tblvalidity = $('<p class="col2">').html("<b>validity</b><br>"); var tblprice = $('<p class="col3">'); var tbldescription = $('<p class="row2">').html("<b>description</b><br>"); var endline =$('<div class="end">'); tblpara.append('<div class="para">' + plan.talktime + '</div>'); tblvalidity.append('<div class="para">' + plan.validity + '</div>'); tblprice.append('<div class="col3para">' + plan.price + '</div>'); tbldescription.append('<div class="para">' + plan.description + '</div>'); console.log(plan); $(".content").append(tblpara).append(tblvalidity).append(tblprice).append(tbldescription).append(endline); }); }); });
i need create similar json this:
{"special_recharge":[ {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"}, {"talktime":"300", "validity":"lifetime","price":"rs 300", "description":"200 full talktime"} ]}
and run same function it.i need json syntax , running same function both of arrays.
there 2 json headers "full_talktime" , "special_recharge", there must identify data(header) going , may u r using 2 separate ajax calls that.
so depending on condition first read json data data.special_recharge / data.full_talktime, eg var datafromdb = data.special_recharge & var datafromdb = data.full_talktime
and call ur function loop :
$.each(datafromdb, function(index, plan) { ...
Comments
Post a Comment