I'm doing a jQuery AJAX post like this:
var form = $("#formid");
form.submit(function()
{
$.ajax(
{
type: "POST",
url: form.attr("action"), // points to NewClient
data: form.serialize(),
success: function(msg) { alert('ok ' + msg); },
error: function(req, status, err) { alert('err=' + err + ' status=' + status); }
});
return false;
});
On the ASP.MVC side I have something like this:
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult NewClient()
{
// just a test...
return null;
}
What's the right result type for the NewClient function for jQuery to work right? As is right now it works in FF and Chrome, but fails in IE8 (works in IE7) -- i.e. in IE8 I get the error alert (edit: the error was because of a "debugger;" call in the JS call). In any case, what's the recommended way to:
- Pass a form to ASP.NET MVC via jQuery (the $().serialize() seems to work fine, is this the recommended way?)
- From the server side to return either Success or Failure, and if it fails some kind of message I could display to the client. How do I tell jQuery that the method / call failed or not?
Thanks.
EDIT:
The html looks like this:
<form id="formid" action="/client/newclient">
... input fields ...
</form>