讀返回對象在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