日期:2014-05-18  浏览次数:20340 次

请教:为什么获取不到json对像的值?
function GetCity() {
  var proid = $("#ProID").val();
  $("#CityID").empty();
  $.ajax({
  url: "/Registers/GetCityByProID?id=" + proid,
  type: 'GET',
  success: function (json) {
  var html = '';
  for (var i = 0; i < json.length; i++) {
  html += '<option value="' + json[i].value + '">' + json[i].text + '</option>';
  }
// alert(html);
  $(html).appendTo($("#CityID"));

  }
  });
  }


为什么得到的值总是:undefined,怎样才真正获取数据,哪里出问题了,请高手帮帮忙!

------解决方案--------------------
JScript code

function GetCity() {
  var proid = $("#ProID").val();
  $("#CityID").empty();
  $.ajax({
  url: "/Registers/GetCityByProID?id=" + proid,
  type: 'GET',
  dataType: 'json' //增加一个
  success: function (json) {
      alert(json);
  },
  error: function(msg) { //增加这个,看看是什么出错
      alert(msg.responseText);
  }
  });
  }