使用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)
相关文章:
- 在一个循环中读取xml文件的所有节点
- 未捕获的typeerror无法读取属性'0'for循环中未定义的
- 在 for 循环中从同名表中读取文本值
- NodeJS - 逐行读取函数 + while 循环
- 循环中的 Javascript 引用:“未捕获的类型错误:无法读取未定义的属性'值'”
- 无法读取未定义的属性“打开”.谷歌地图信息窗口循环
- 循环访问和读取 JSON 数据
- 在循环中使用 DOM 时:未捕获的类型错误:无法读取空错误的属性“已检查”
- Javascript,'for in' 循环将对象读取为字符串
- 对于循环添加被读取为未定义的对象
- 通过循环读取数据并将其插入数组
- 承诺在 NodeJS 中循环和文件读取
- 未捕获的类型错误:尝试在 jquery 中循环访问 json 数组时,无法读取未定义的属性“create”
- 对于循环中 JSLint 错误消息:无法从未定义读取属性“行”
- 不读取 while 循环中表单元素第一次迭代 ASP.NET
- 未捕获的类型错误: 无法读取未定义的属性“循环”
- 循环读取图像,等待其加载
- 对象.keys forEach循环读取整个对象
- 使用getJSON函数从while循环读取数据
- imacros-jave循环读取新的csv行