Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net jQuery中的webservice返回集合类型_Asp.net_Jquery - Fatal编程技术网

Asp.net jQuery中的webservice返回集合类型

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:

我有一个返回列表对象的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: "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或不是对象。