我正在调用来自ajax调用函数的代码。 我刚刚创建了一个Post方法,它返回一个列表。 我只想检查客户端的值。因此,只需输出一条警报消息并将response.d作为参数传递。但它返回object,Object而不是实际值。 我想知道获取值的确切方法吗?来自ajax调用的函数背后的调用代码并逐项显示
[WebMethod]
public static List<person> Post()
{
List<person> List = new List<person>();
person p1 = new person();
p1.name = "Sourav";
p1.surname = "Kayal";
List.Add(p1);
person p2 = new person();
p2.name = "Sourav";
p2.surname = "Kayal";
List.Add(p2);
return List;
}
}
public class person
{
public string name { get; set; }
public string surname { get; set; }
}
<script>
$(document).ready(function() {
$.ajax({
type: "POST",
url: "JavaScript.aspx/Post",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var names = response.d;
alert(names);
},
failure: function (response) {
alert(response.d);
}
});
});
</script>
您需要解析JSON对象获得值.. – Murtaza 2014-09-03 04:22:12