我遇到了回调问题。我什至没有在 Firebug 中遇到错误。如果我在 getjson 调用之前和之后发出警报,则两个警报都会显示,但 getjson 调用不会触发。
public ActionResult TestPage()
{
return View();
}
public ActionResult LoadMapLonLats(int mapId)
{
//some code
return Json(_myMaps);
}
$("#Search").click(function() {
$.getJSON("LoadMapLonLats", { mapId: 73 }, loadDbMap);
});
function loadDbMap(maps) {
alert('m');
$.each(maps, function(i) {
alert(maps[i]);
});
}
只要我在没有参数的情况下离开 TestPage 就可以了。如果我向 TestPage(int id) 添加参数,则对 LoadMapLonLats 的回调不起作用。似乎很奇怪。当然 TestPage 是我正在加载的页面,所以在渲染页面之前我需要在这里做一些工作。不知道为什么向视图添加参数会破坏对另一个函数的回调。
//this breaks he callback to LoadMapLonLats
public ActionResult TestPage(int id)
{
return View();
}
有任何想法吗?似乎这可能是相关的,如果不是抱歉,我可以发布一个新线程。