在Phonegap中显示JSON响应数组
很快的问题 我有返回JSON数组的webservice 我想在phonegap应用程序中显示JSON数组 我该怎么做 到目前为止,我一直在尝试这个 但它不起作用在Phonegap中显示JSON响应数组,json,cordova,Json,Cordova,很快的问题 我有返回JSON数组的webservice 我想在phonegap应用程序中显示JSON数组 我该怎么做 到目前为止,我一直在尝试这个 但它不起作用 $(document).ready(function () { $.jsonp({ url: 'getevents.php', callbackParameter: 'callback', success: function (data, status) { //$('#your-tweets'
$(document).ready(function () {
$.jsonp({
url: 'getevents.php',
callbackParameter: 'callback',
success: function (data, status) {
//$('#your-tweets').append('<li>The feed loads fine');
$.each(data, function (i, item) {
var tweet = item.title;
$('#your-tweets').append('<li>' + tweet);
});
},
error: function () {
$('#your-tweets').append('<li>There was an error loading the feed');
}
});
但是有了这段代码,我得到了一个错误,$。jsonp不是一个函数
如果有一些在线教程,请提供链接给我
我也尝试过这个函数
但不知何故,我无法找到从Web服务传递返回数组的位置
function readJSONData() {
$.getJSON("getevents.php",function(data){
if(data) {
var json_data;
$('#read-data').hide();
$('.demo-table').show();
$.each(data, function(i,event){
json_data = '<tr>'+
'<td valign="top">'+
'<div class="feed_title">'+event.title+'</div>'+
'<div>'+event.description+'</div>'+
'</td>'+
'</tr>';
$(json_data).appendTo('#demo-table-content');
});
} else {
json_data += '<tr>'+
'<td valign="top">No Tutorials Found</td>'+
'</tr>';
$(json_data).appendTo('#demo-table-content');
}
});
函数readJSONData(){
$.getJSON(“getevents.php”,函数(数据){
如果(数据){
var-u数据;
$(“#读取数据”).hide();
$('.demo table').show();
$。每个(数据、函数(i、事件){
json_数据=“”+
''+
''+事件.标题+''+
''+事件.描述+''+
''+
'';
$(json_数据).appendTo(“#演示表内容”);
});
}否则{
json_数据+=''+
“未找到教程”+
'';
$(json_数据).appendTo(“#演示表内容”);
}
});
}
我可以在firebug中看到,在ajax请求中,它返回事件
数组,但在页面上,我得到的是未定义
,而不是数据
谢谢您,非常感谢使用此原型。而非事件是一个数组,因此您必须检查数组中的元素,即
数据。事件[索引]
此外,您没有任何参数data.event.desc,因此引用该元素将导致未定义
<html>
<body>
<a href="#" id="getdata-button">Get JSON Data</a>
<div id="showdata"></div>
</body>
</html>
$(document).ready(function(){
//attach a jQuery live event to the button
$('#getdata-button').live('click', function(){
$.getJSON('http://dev.app.horsebuzz.com/dbconnection/getevents.php', function(data) {
//alert(data); //uncomment this for debug
//alert (data.item1+" "+data.item2+" "+data.item3); //further debug
for(var i=0;i<data.event.length;i++){
$('#showdata').html("<p>item1="+data.event[i].title+" item2="+data.event[i].start_date+" item3="+data.event[i].location+"</p>");
}
});
});
});
$(文档).ready(函数(){
//将jQuery live事件附加到按钮
$(“#获取数据按钮”).live('单击',函数()){
$.getJSON('http://dev.app.horsebuzz.com/dbconnection/getevents.php,函数(数据){
//警报(数据);//取消对此的注释以进行调试
//警报(data.item1+“”+data.item2+“”+data.item3);//进一步调试
对于(var i=0;iplease)jsFiddle上的共享代码,我将帮助您对其进行排序out@sunil这是链接,你可以转到我在那里使用的web服务,查看数组格式,也可以先添加Jquery和Jquery mobile js文件,这太完美了。很抱歉延迟重播,但感谢你在这方面的帮助…非常感谢
<html>
<body>
<a href="#" id="getdata-button">Get JSON Data</a>
<div id="showdata"></div>
</body>
</html>
$(document).ready(function(){
//attach a jQuery live event to the button
$('#getdata-button').live('click', function(){
$.getJSON('http://dev.app.horsebuzz.com/dbconnection/getevents.php', function(data) {
//alert(data); //uncomment this for debug
//alert (data.item1+" "+data.item2+" "+data.item3); //further debug
for(var i=0;i<data.event.length;i++){
$('#showdata').html("<p>item1="+data.event[i].title+" item2="+data.event[i].start_date+" item3="+data.event[i].location+"</p>");
}
});
});
});