ajax读取json显示undefined

functionAjaxGetData(index,size){$.ajax({url:"<%=basePath%>Inventory/depotWarnlistajax... function AjaxGetData(index, size) {
   $.ajax({
   url: "<%=basePath%>Inventory/depotWarnlistajax",
   type: "get",
   data: "pagenum=" + index + "&pagesize=" + size,
   //dataType: "json",
//contentType: "application/JSON",
   success: function (warns) {
alert(warns); 
  var html = "";
warns=eval("(" + warns + ")");
   for(var i=0;i<warns.length;i++){
   html += "<tr>";
   html += "<td>"+warns[i].Prod_No+"</td>";
   html += "<td>"+warns[i].Prod_Name+"</td>";
   html += "<td>"+warns[i].Prot_Name+"</td>";
   html += "<td>"+warns[i].Prod_Model+"</td>";
  html += "<td>"+warns[i].Prod_Unit+"</td>";
   html += "<td>"+warns[i].Inventory_Num+"</td>";
   html += "<td>"+warns[i].ProMin+"</td>";
html += "<td>"+warns[i].ProMax+"</td>";
   html += "</tr>";
   }
warns中的数据如下:
[{"supp_Id":"2","prod_No":"1","prod_Name":"钢笔","prod_Model":"小型","prod_Unit":"往往外","proT_ID":"1","proMin":"2","proMax":"6","prod_Status":"0","prod_Remark":"2","prod_Ucers":"2","prod_Prices":2,"prot_Name":"圆珠笔","inventory_Num":"1.0"},{"supp_Id":"2","prod_No":"2","prod_Name":"1","prod_Model":"1","prod_Unit":"1","proT_ID":"1","proMin":"2","proMax":"8","prod_Status":"0","prod_Remark":"2","prod_Ucers":"2","prod_Prices":2,"prot_Name":"圆珠笔","inventory_Num":"10.0"}]

说明json中是有值的,可是warns[i].Prod_No为undefined。这是为什么呢。
展开
 我来答
xiii130
2013-09-02 · 知道合伙人软件行家
xiii130
知道合伙人软件行家
采纳数:817 获赞数:2867
爱好编程,在工作中积累了比较丰富的经验。愿与大家共同进步。

向TA提问 私信TA
展开全部
<script type="text/javascript">
var a = '[{"supp_Id":"2","prod_No":"1","prod_Name":"钢笔","prod_Model":"小型","prod_Unit":"往往外","proT_ID":"1","proMin":"2","proMax":"6","prod_Status":"0","prod_Remark":"2","prod_Ucers":"2","prod_Prices":2,"prot_Name":"圆珠笔","inventory_Num":"1.0"},{"supp_Id":"2","prod_No":"2","prod_Name":"1","prod_Model":"1","prod_Unit":"1","proT_ID":"1","proMin":"2","proMax":"8","prod_Status":"0","prod_Remark":"2","prod_Ucers":"2","prod_Prices":2,"prot_Name":"圆珠笔","inventory_Num":"10.0"}]';

var b = eval('(' + a + ')');

for(var i=0;i<b.length;i++){
    alert(b[i].prod_No);
}
</script>

我测试了你的代码,确实是可以alert出值的,和大小写有没有关系呢,因为我发现你的json数据和处理函数的大小写不一样。

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式