读返回对象在JQuery中 4分钟前| LINK读返回对象在JQuery中
我创建了一个WCF服务,返回GenericList对象。我需要阅读使用jQuery在客户端该对象,但可以得到它的工作:
下面是我的代码:
SVC方法:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public CommentList GetComments()
{
Comments oComment1 = new Comments();
oComment1.Title = "AMaking hay when the sun shines";
oComment1.Author = "Plan_A";
oComment1.CommentText = "AI like hay almost as much as I like sun. Just joking";
Comments oComment2 = new Comments();
oComment2.Title = "Making hay when the sun shines";
oComment2.Author = "Plan_B";
oComment2.CommentText = "I like hay almost as much as I like sun. Just joking";
CommentList oCommentList = new CommentList();
oCommentList.Comment.Add(oComment1);
oCommentList.Comment.Add(oComment2);
return oCommentList;
}
在客户端
jQuery脚本:
$('#CommentsButton').click(function() {
$.getJSON('http://localhost:55679/RESTService.svc/GetComments?callback=?', function (data) {
alert(data);
});
响应我越来越(通过Inspect元素 - 铬工具)
jsonp1363710839478({"Comment":[{"Author":"Plan_A","CommentText":"AI like hay almost as much as I like sun. Just joking","Title":"AMaking hay when the sun shines"},{"Author":"Plan_B","CommentText":"I like hay almost as much as I like sun. Just joking","Title":"Making hay when the sun shines"}]});
问题是什么? – Matus 2013-03-19 16:57:07
'alert(GetComments);'中定义的'GetComments'在哪里? – 2013-03-19 16:59:58
@Matus我需要读取从 – Khan 2013-03-19 17:07:04