当前位置: 代码迷 >> ASP.NET >> json[0].CodeID值为undefined解决方法
  详细解决方案

json[0].CodeID值为undefined解决方法

热度:1442   发布时间:2013-02-25 00:00:00.0
json[0].CodeID值为undefined
求大侠帮忙瞅瞅,为什么json[0].CodeID值为undefined,调试var json = msg.d,json中数据为[{"CodeID":"380246","CodeSN":"12961uq2y9anin","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"1"},{"CodeID":"380245","CodeSN":"129606mvpay17i","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"2"},{"CodeID":"380244","CodeSN":"1296k10yw10i1x","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"3"},{"CodeID":"380243","CodeSN":"1296abeyeqewet","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"4"},{"CodeID":"380242","CodeSN":"1296pf6pju0gnw","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"5"},{"CodeID":"380241","CodeSN":"12961o3onz217p","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"6"},{"CodeID":"380240","CodeSN":"1296iig8orznla","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"7"},{"CodeID":"380239","CodeSN":"1296p7vn6bqebu","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"8"},{"CodeID":"380238","CodeSN":"12968x088slhxc","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"9"},{"CodeID":"380237","CodeSN":"1296cvyknhbazp","CodePWD":"123456","Addtime":"2011-6-13 17:22:15","RowNumber":"10"}]

function Bind(id) 
  {
  var cuid=parseInt(id);
  var para = "{'currentpage':" + cuid + "}";
  $.ajax({
  type: "POST",
  url: "TestAjaxPage.aspx/getInfo",
  data: para,
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  timeout: 60000, 
  error:function (XMLHttpRequest, textStatus, errorThrown)
  {
  alert("error:"+errorThrown);
  },
  success: function (msg) {
  if (msg.d == null) {
  return;
  }  
  var json = msg.d;
  alert(json[0].CodeID);
  var str = "<table><tr><td>编号</td><td>SN号</td><td>密码</td><td>添加时间</td><td>操作</td></tr>";
  for (var i = 0; i < json.length; i++) {
  str += "<tr><td>" + json[i].CodeID + "</td><td> " + json[i].CodeSN + "</td><td>"+json[i].CodePWD+"</td><td>" + json[i].Addtime + "</td><td>删除</td></tr>";  
  }
  str += "</table>";
  $("#divResult")(str);
  }
  相关解决方案