submitting an asp.net MVC 3 form using jquery ajax -


i working on asp.net mvc 3 application , have jquery dialogue ok button. on click of ok want submit form using jquery ajax.

my ajax call looks this:

$("#free-trial").dialog({    autoopen: false,    autoresize: true,    buttons: {        "ok": function () {            if (notvalid()) {                $(".ui-dialog-titlebar").hide();                $("#dialog-freetrial-insufficientdata").dialog({ dialogclass: 'transparent' });                $("#dialog-freetrial-insufficientdata").dialog("open");            }            else {                $('#frmcreatetrialaccount').live('submit', function (e) {                    e.preventdefault();                    $.ajax({                        cache: false,                        async: true,                        type: "post",                        url: $(this).attr('action'),                        data: $(this).serialize(),                        success: function (data) {                            alert(data);                        }                    });                });                jquery(this).dialog('close');            }        }    },    open: function () {        $('.ui-dialog-buttonset').find('button:contains("ok")').focus();        $('.ui-dialog-buttonset').find('button:contains("ok")').addclass('customokbutton');    } 

});

where form looks this:

@using (html.beginform("createtrialaccount", "home", formmethod.post,                new { id = "frmcreatetrialaccount" } )) {  } 

and controller action looks this:

[httppost] public jsonresult createtrialaccount(formcollection form) {     return json("dummy data"); } 

but form not submitted on method.

i have these files included in layout page:

<link href="@url.content("~/content/css/smoothness/jquery-ui-1.10.0.custom.css")" rel="stylesheet" type="text/css"  media="screen"/> <script src="@url.content("~/scripts/jquery-1.9.1.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery-ui-1.10.2.custom.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> 

please suggest me solution this.

oh sorry comment made, issue binding form's submit action should have been submitting already. if want bind form's submit declare outside $("#free-trial").dialog({. can have ajax post method in separate function can call in both binding code , in $("#free-trial").dialog({.

var form = $('#frmcreatetrialaccount'); $.ajax({     cache: false,     async: true,     type: "post",     url: form.attr('action'),     data: form.serialize(),     success: function (data) {         alert(data);     } }); 

so make clear remove following lines of code:

$('#frmcreatetrialaccount').live('submit', function (e) { e.preventdefault(); // , ending  }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -