使用 getJSON 函数读取 while 循环数据
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 the response format type
header("Content-Type: application/json");
//converts any PHP type to JSON string
echo json_encode($name);
?>
我正在使用上面的 while 循环来获取 JSON 格式,然后我使用这个
$(function() {
//Set Url of JSON data. make sure callback is set with a '?' to overcome the cross domain problems with JSON
var url = "http://127.0.0.1/olem.app/tab/api/js_on.php?get=json&subscribers=incomplete";
//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the 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);
});
});
显示 <div id="js_inc_month"></div>
到目前为止我还没有定义,我该如何解决这个问题
因为这个:
$name = array("response" => $data);
您将必须像这样访问数据:
json.response[0].result_paid
如果有任何不清楚的地方,您可以简单地:
console.log(json)
在响应中查看接收到的对象的外观。
<?
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 the response format type
header("Content-Type: application/json");
//converts any PHP type to JSON string
echo json_encode($name);
?>
我正在使用上面的 while 循环来获取 JSON 格式,然后我使用这个
$(function() {
//Set Url of JSON data. make sure callback is set with a '?' to overcome the cross domain problems with JSON
var url = "http://127.0.0.1/olem.app/tab/api/js_on.php?get=json&subscribers=incomplete";
//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the 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);
});
});
显示 <div id="js_inc_month"></div>
到目前为止我还没有定义,我该如何解决这个问题
因为这个:
$name = array("response" => $data);
您将必须像这样访问数据:
json.response[0].result_paid
如果有任何不清楚的地方,您可以简单地:
console.log(json)
在响应中查看接收到的对象的外观。