Asp.net jQuery中的webservice返回集合类型
我有一个返回列表对象的ASP.NET Web服务Asp.net jQuery中的webservice返回集合类型,asp.net,jquery,Asp.net,Jquery,我有一个返回列表对象的ASP.NET Web服务 public class Students { public string StudentName { get; set; } public int Age { get; set; } } 我使用这个jQuery代码访问这个Web服务 $.ajax({ type: "POST", url: "/Students.asmx/GetStudents", data: "{}", contentType:
public class Students
{
public string StudentName { get; set; }
public int Age { get; set; }
}
我使用这个jQuery代码访问这个Web服务
$.ajax({
type: "POST",
url: "/Students.asmx/GetStudents",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#myDiv").html(msg.d);
}
});
但我得到的只是对象
如何获取该对象中的数据?在jquery中(当您检查jquery对象时),一切都是[object] 您实际上得到了一个学生对象数组;您可以像这样迭代结果
for (x = 0; x < msg.length; x++) {
alert(msg[x].StudentName);
}
for(x=0;x
在jquery中(当您检查jquery对象时),一切都是[Object Object]
您实际上得到了一个学生对象数组;您可以像这样迭代结果
for (x = 0; x < msg.length; x++) {
alert(msg[x].StudentName);
}
for(x=0;x
非常感谢..我忘了提到我使用的是jmsajax而不是$.ajax..所以当我按照你的建议做时..我得到d.length为null或不是对象。非常感谢..我忘了提到我使用的是jmsajax而不是$.ajax..所以当我按照你的建议做时..我得到d.length为null或不是对象。