I have a really simple request, but I'm stuck on how to implement the ajax stuff.
Basically on document.ready, I've got a javascript method that checks for a "UTCOffset" cookie, and if it doesn't exist, it will do a "behinds the scenes" ajax post to a controller that sets the offset.
Basically I'm trying to make it so that the user doesn't have to manually input their UTC offset.
How would I implement the Ajax post to the Action? Is the action 开发者_C百科supposed to be a "Sub" instead of a "Function" (since functions are supposed to return something.
You can use $.post (or regular $.ajax).
$.post("home/save", data, function (data) {
// handle result, or ignore it if you don't care.
});
Your action method might look like this:
[HttpPost]
public ActionResult Save(int someId)
{
// do the foo
var result = new { code: 0 }; // or code : 1 if error occured (for example)
return Json(result);
}
精彩评论