JsonResult 操作未被触发
我的 UpdatesController
中有一个带有以下签名的操作方法:
public JsonResult GetUpdates(DateTime lastUpdate)
在我看来,我有以下代码来调用该方法(此时它只是在按钮的 onclick 事件上进行测试,具有 id clickme 的按钮):
$(document).ready(function(){
$("#clickme").click(function(){
alert("Before");
$.getJSON("http://localhost/Updates/GetUpdates", "04/05/2011 11:44:37", function(data){ alert(data); });
alert("After");
});
});
点击事件触发,并且 Before
和 After
警报都触发,但是我没有收到任何数据,因为我没有收到 json 警报数据。我还在 GetUpdates
方法中设置了一个断点,并且从未命中该断点,我认为这表明请求未发送?
会不会是参数有问题?
谢谢
更新
所以我终于在 Visual Studio 中单步执行了,并且操作方法运行没有错误。但是,警报未显示,如果我查看 Firebug 中的“网络”选项卡,我会收到针对此特定请求的 500 错误?
I have an action method in my UpdatesController
with the following signature:
public JsonResult GetUpdates(DateTime lastUpdate)
In my view, I have the following code to call the method (at this moment in time it's just on a button's onclick event for testing, the button having id clickme):
$(document).ready(function(){
$("#clickme").click(function(){
alert("Before");
$.getJSON("http://localhost/Updates/GetUpdates", "04/05/2011 11:44:37", function(data){ alert(data); });
alert("After");
});
});
The click event fires, and the Before
and After
alert's both fire, however I don't get any data back as I get no alert with json data. I have also set a breakpoint in the GetUpdates
method and the breakpoint is never hit, which I believe indicates that the request isn't getting sent?
Could there be some issue with the parameter?
Thanks
Update
So I finally got it to step through in Visual Studio and the action method runs with no errors. However, the alert isn't shown and if I look at the Net tab in Firebug I get a 500 error for this specific request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试更改它来执行此操作:
可能没有找到正确的操作,因为可能没有匹配的路线。
运行 fiddler 并检查响应是什么将是我要尝试的下一步
编辑:
还要确保如果您使用的是 MVC 2,您的 Json 调用将 JsonRequestBehavior.AllowGet 作为参数。例如
Try changing it to do this:
It's possible it's not finding the correct action as there may not be a matching route.
Running fiddler and checking what the response is would be the next step I would try
Edit:
Also make sure that your Json call has JsonRequestBehavior.AllowGet as a parameter if you're using MVC 2. e.g.