【发布时间】:2012-07-11 04:04:30
【问题描述】:
控制器
public JsonResult TeamInfo(string teamName)
{
teamDA = new TeamDataAccess();
var teamInfo = teamDA.TeamInfo(teamName);
System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
new System.Web.Script.Serialization.JavaScriptSerializer();
string sJSON = oSerializer.Serialize(teamInfo);
JsonResult jsonResult
=new JsonResult(){ JsonRequestBehavior = JsonRequestBehavior.AllowGet };
jsonResult.Data = sJSON; // first i give this.
jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return jsonResult;
}
从 jQuery 调用控制器
$.ajax({
url: 'Team/TeamInfo/' + teamName,
success: function (data) {
$('#teamDetails').html(data);
alert('Load was performed.');
$("#dialog-modal").dialog("open");
}
});
在调试时,我可以看到它一直执行到控制器 return jsonResult; 的最后一行,但 alert('Load was performed.'); 不可见。
你知道它没有进入成功部分的原因是什么吗?服务器端没有错误。非常感谢任何帮助。
编辑
当我在 ajax 调用中添加 error 时。它显示错误 500(内部服务器错误)。我如何找到这个问题?
【问题讨论】:
-
如果直接把结果作为HTML放到页面的DOM中,为什么还要发回
JsonResult呢?尝试注释掉$('#teamDetails').html(data);.... 看看会发生什么。 -
没什么。它只是完成了控制器中的功能,并没有进入成功。是否需要在我的代码中添加?
-
从浏览器调用您的操作,而不是通过 ajax 调用。服务器将为您返回错误页面。或者在调试模式下运行。
-
是的,我遇到了问题。
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request。请查看我的更新代码
标签: c# asp.net-mvc json jquery asp.net-ajax