Javascript 使用getJSON函数读取while循环数据
要显示Javascript 使用getJSON函数读取while循环数据,javascript,jquery,arrays,getjson,Javascript,Jquery,Arrays,Getjson,要显示到目前为止,我还没有定义,如何才能扭转这一局面,因为: $(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=incom
到目前为止,我还没有定义,如何才能扭转这一局面,因为:
$(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);
});
});
您必须访问以下数据:
$name = array("response" => $data);
如果有任何不清楚的地方,您可以简单地:
json.response[0].result_paid
在响应中查看接收对象的外观。因此:
$(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);
});
});
您必须访问以下数据:
$name = array("response" => $data);
如果有任何不清楚的地方,您可以简单地:
json.response[0].result_paid
在响应中查看接收到的对象的外观。我的json数据如下所示。{“回复”:{“获取”:“json”,“订阅者”:“付费”,“0”:{“结果付费”:“订阅者1”,“错误代码”:0,“结果付费详情”:“MPESA”,“结果时间”:“2015-07-13 13:58:19”,“结果地点”:“1-pkr HS”},“1”:{“结果付费”:“订阅者2”,“错误代码”:0,“结果付款详细信息”:“MPESA”,“结果付款时间”:“2015-07-11 13:15:26”,“结果付款地点”:“1-pkr HS”}}}}}您不应该将数组与对象混合使用。这会增加迭代的难度。但是,您需要的数据位于
json.response[0]。结果付款
和json.response[1]。结果付款
或者添加$data['results']=array();
然后在php中使用$data['results'][]=…
(然后在回调中迭代json.response.results
)或者添加get
和subscribers
作为$name
对象的键,并使用简单的for循环迭代json.response
。我的json数据如下所示。{“response”:{“get”:“json”,“subscribers”:“paid”,“0”:{“result\u paid”:“subscriber1”,“err code”:“0,”结果付款详情:“MPESA”,“结果付款详情”:“2015-07-13 13:58:19”,“结果地点”:“1-pkr HS”},“1”:{“结果付款详情”:“认购人2”,“错误代码”:0,“结果付款详情”:“MPESA”,“结果时间”:“2015-07-11 13:15:26”,“结果地点”:“1-pkr HS”}您不应该将数组与对象混合使用。这会增加迭代的难度。但是,您需要的数据位于json.response[0]。result\u paid
和json.response[1]。result\u paid
在php中添加$data['results']=array();
然后添加$data['results'][]=…
(然后在回调中迭代json.response.response
)或添加get
和subscribers
作为$name
对象的键,并使用简单的for循环迭代json.response
。