在我的asp.net mvc项目中尝试我的一点点JSON。我有以下观点:从asp.net获取JSON不会使用getJSON返回任何内容
<asp:Content ID="Content3" ContentPlaceHolderID="NavigationPlaceholder" runat="server">
<script type="text/javascript">
$(document).ready(function() {
alert('loaded');
$.getJSON('/Students/LoadYearRoot', null, function (data, textStatus) {
alert('test');
});
});
</script>
</asp:Content>
及以下控制器(请注意,我评论了我的数据库调用,并只是字符串:
public JsonResult LoadYearRoot()
{
GWSSchool school = SchoolHelper.GetSchool();
//List<GWSYear> years = yearRepository.GetAll(school.Id);
List<string> strings = new List<string>() { "first", "second", "third" };
JsonResult result = this.Json(strings);
return result;
}
观察认为我得到我的第一次尝试警报,显示“加载”,但然后它停止,我从来没有进入回调函数,我测试了我用控制器使用断点,所以结果似乎是正确的。网络完全是这样的,我错过了什么?
谢谢,它现在有效。并感谢网址的伟大建议,它非常有用。 – 2012-02-13 21:01:34