2
我有我从本地mysql获得的以下json对象。使用Jquery Json将外部数据加载到phonegap中P
<([{"ID":"1","Title":"Chicken & Chili","Price":"$8.99","ImageURL":"\/images\/dinner\/chicchili.jpg","Serves":"2","Description":"This unique and delicious chicken chili is a much-requested meal around our house. I think you'll find it's a nice change of pace from the typical beef version."},{"ID":"2","Title":"Chicken Franchase","Price":"$9.99","ImageURL":"\/images\/dinner\/chicfran.jpg","Serves":"2","Description":"Served in a lemon and butter sauce"},{"ID":"3","Title":"Salmon","Price":"$14.99","ImageURL":"\/images\/dinner\/salmon.jpg","Serves":"1","Description":"A simple soy sauce and brown sugar marinade, with hints of lemon and garlic, are the perfect salty-sweet complement to rich salmon fillets."}]);
我用下面的代码来获取json对象到iPhone模拟器。我成功地在屏幕上获得标题和价格,但不是图像。是否有任何方法获取图像?或者我在编码中遗漏了一些东西?请给我一些建议?
$(document).ready(function(){
var output = $('#output');
$.ajax({
url: 'http://localhost/Backend/getDinner.php',
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
$.each(data, function(i,item){
var Menu_Dinner = '<li><a href="detail.html?id=' + item.ID + '">' +
'<img src="images/dinner/'+ item.ImageURL + '">' +
'<h2 class="ui-li-heading">' + item.Title + '</h2 >' +
'<h2>' + 'Price: ' + item.Price + '</h2>'+ '</a></li>';
output.append(Menu_Dinner);
});
},
error: function(){
output.text('There was an error loading the data.');
}
}); });
尝试删除图像路径上的前导斜杠。 – Archer 2013-03-26 14:21:38