我正在尝试从我的 asp.net mvc webservice 接收一些 json。ASP.NET:
public JsonResult getMessagesFromFriend(string email, string friendmail) {
DataLayer.Repository.Classes.DataLayer dl = DataLayer.Repository.Classes.DataLayer.Instance;
return Json(dl.getMessagesFromFriend(email, friendmail);
}
当我使用 http 分析器发送测试帖子消息时,我得到:
Tue May 01 11:24:59 CEST 2012
----------------------------------------
POST http://xxx.xxx.xxx.xxx/tracy/chat/getMessagesFromFriend?email=linsy&friendmail=djcarre
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 01 May 2012 09:25:04 GMT
Content-Length: 309
----------------------------------------
----------------------------------------
[{"sender":"viagsm","receiver":"djcarre","datetime":"28/04/2012 16:55:33","message":"msg1"},{"sender":"viagsm ","receiver":"djcarre","datetime":"28/04/2012 16:55:59","message":"msg2"},{"sender":"Philippe C","receiver":"linsy","datetime":"28/04/2012 16:56:10","message":"test3"}]
----------------------------------------
所以它返回了我的json。我的 javascript 代码如下所示:
$.post("http://xxx.xxx.xxx.xxx/tracy/chat/getMessagesFromFriend?email=linsy&friendmail=djcarre", function(data) {
if (data.length > 0) {
for (x in data) {
$("#chatarea").html(
$("#chatarea").html() +
"<p><b>" +
data[x].sender + "</b>" +
" (" + data[x].datetime.match(/(\d+:\d+:\d+)/)[1] + ") : " +
data[x].message + "</p>");
}
}
}, "json");
}
当我查看萤火虫时,帖子已发送,我得到 200 好,但答案保持为空。我也试过 $.ajax 和
error:function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
}
但我只收到一个空警报,所以有一个错误,但我不知道是哪一个以及如何解决它。我希望有人知道如何帮助我。
亲切的问候