javascript - Using getJSON function to read from while loop data -
<? while ($row_previous_bill = $res_previous_bill->fetchrow()) { $bill = $row_previous_bill[6]; $bill_2 = $row_previous_bill[2]; $bill_3 = $row_previous_bill[3]; $bill_4 = $row_previous_bill[1]; $hotspot_location = $row_previous_bill[5]; $data[] = array("result_paid" => $bill, "err_code" => 0, "result_payment_details" => $bill_3, "result_time" => $bill_4, "result_location" => $hotspot_location); } $name = array("response" => $data); //sets response format type header("content-type: application/json"); //converts php type json string echo json_encode($name); ?>
i using while loop above json format, use this
$(function() { //set url of json data. make sure callback set '?' overcome cross domain problems json var url = "http://127.0.0.1/olem.app/tab/api/js_on.php?get=json&subscribers=incomplete"; //use jquery getjson method fetch data url , create our unordered list relevant data.$(username) $.getjson(url,function(json){ var html = "" + json.result_paid + ""; //a little animation once fetched $('#js_inc_month').animate({ opacity: 0 }, 5, function(){ $('#js_inc_month').html(html); }); $('#js_inc_month').animate({ opacity: 1 }, 5); }); });
to display <div id="js_inc_month"></div>
up point getting undefined, how turn around this
because of this:
$name = array("response" => $data);
you have access data that:
json.response[0].result_paid
if unclear simply:
console.log(json)
in response see how received object looks like.
Comments
Post a Comment