Reputation: 6730
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?
Upvotes: 1
Views: 215
Reputation: 35793
Try changing it to do this:
$.getJSON("http://localhost/Updates/GetUpdates", { lastUpdate: "04/05/2011 11:44:37" }, function(data){ alert(data); });
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.
return Json(obj, JsonRequestBehavior.AllowGet);
Upvotes: 1