为啥都获取到了数据但就是不能循环出来呢

lghyt 发布于 2016/06/12 12:21
阅读 370
收藏 0
PHP
{code: 200, datas: [{goods: {title: "女u8fy",…}}]}
code:200
datas:[{goods: {title: "女u8fy",…}}]
0:{goods: {title: "女u8fy",…}}
goods:{title: "女u8fy",…}
item:[{goods_id: "237", goods_name: "数据11", goods_promotion_price: "44.00", goods_price: "44.00",…},…]
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}
title:"女u8fy"    

上面是ajax获取到的json

但就是循环不出来,循环代码如下

<script type="text/html" id="goods">
	<div class="nctouch-home-block item-goods">
	<% if (title) { %>
		<div class="tit-bar"><%= title %></div>
	<% } %>
		<ul class="goods-list">
		<% for (var i in item) { %>
			<li>
				<a href="tmpl/product_detail.html?goods_id=<%= item[i].goods_id %>">
					<div class="goods-pic"><img src="<%= item[i].goods_image %>" alt=""></div>
					<dl class="goods-info">
						<dt class="goods-name"><%= item[i].goods_name %></dt>
						<dd class="goods-price">¥<em><%= item[i].goods_promotion_price %></em></dd>
					</dl>
				</a>
			</li>
		<% } %>
		</ul>
	</div>
</script> 




加载中
0
此用户已关机
此用户已关机
你需要从返回的json数据中,先把item弄出来
lghyt
lghyt
其实你说的对,后来我查了一下,是json返回来的数值少了很多,所以不能加载。
0
bodii
bodii

item:[{goods_id: "237", goods_name: "数据11", goods_promotion_price: "44.00", goods_price: "44.00",…},…]
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}



json 返回数据格式有问题

不应该是这样吗?:

item:[
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}]

lghyt
lghyt
json数据没问题
0
a
astars
json_decode($arr,true)
a
astars
回复 @lghyt : 我被你弄笑了
lghyt
lghyt
如果没有用json_decode,会出现我列出的json数据吗?你好好看看,这是常识!
0
bodii
bodii

引用来自“bodii”的评论

item:[{goods_id: "237", goods_name: "数据11", goods_promotion_price: "44.00", goods_price: "44.00",…},…]
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}



json 返回数据格式有问题

不应该是这样吗?:

item:[
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}]

1. 我没有在php 中见过这种写法:for  (var i in item) ??????
2.我没有在json 格式中遍历过这种: item:[{...}]0:...1:... ????? 
3.你应该是遍历item吧,既然遍历item, 你的 i 就应该是键,而item应该是类似:                                      "singers":[ {'id':02,'name':'tom','gender':'男',...},... ] 的格式??????
0
fys91
fys91
body{
background:red
}



0
白眼狼
你这写法也是6、ajax获取的数据配合小脚本+html元素用?
0
MGL_TECH
MGL_TECH
我没看错吧?  ajax获取的东西是客户端的,你竟然用服务端的东西循环客户端的咚咚,,,,<% %>不是 jsp的写法吗 ?
返回顶部
顶部