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。这是为什么呢。 展开
$.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。这是为什么呢。 展开
1个回答
2013-09-02 · 知道合伙人软件行家
关注
展开全部
<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数据和处理函数的大小写不一样。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询