You can invoke your form's submit using .Submit()
success: function (data) {
$('#registerformid').submit(); // right here.
}
Vra
I have a simple ASP.NET MVC Form that has code like the following:
@using (Html.BeginForm(null, null, FormMethod.Post, new
{
action = "https://secure.authorize.net/gateway/transact.dll",
id = "registerformid",
}))
{
@Html.HiddenFor(a => a.RegisterUserInfoLoggedIn.AttendeesId)
...
I've got a JQuery ajax call I do and if that JQuery is successful, I want my form to POST to the action url for further processing.
My JQuery looks like the following,but what I can't figure out is what to put in my JQuery ajax success event such that I post back to the action url, that page responds properly and shows me my new page.
success: function (data) {
if (donationAmount > 0.00) {
$.post("https://secure.authorize.net/gateway/transact.dll", {
x_login: 'xxx',
x_amount: 19.99,
x_description: 'Sample Transaction',
...
}, function(datax) {
this.submit();
});
Oplossing
You can invoke your form's submit using .Submit()
success: function (data) {
$('#registerformid').submit(); // right here.
}
Ander wenke
You can do following.
Return proper json format based on your Action status.
public ActionResult SomeAction()
{
return this.Json(new
{
redirectUrl = "/ControllerName/ActionName",
isRedirect = true
}, JsonRequestBehavior.AllowGet);
}
Redirect to provided page on success method.
$.ajax({
url: '/Home/SomeAction',
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
// redirect to home if true
if (data.isRedirect) {
window.location.href = data.redirectUrl;
}
}
});