ASP.NET MVC 2 Post AJAX from from JavaScript

Posted by ANDyW on Stack Overflow See other posts from Stack Overflow or by ANDyW
Published on 2010-05-31T12:13:49Z Indexed on 2010/05/31 12:23 UTC
Read the original article Hit count: 534

Hi, I got control with strongly typed View, with Ajax.BeginForm(). Now I would like to change submit method from

<input type="submit" id="testClick" value="Submit" />

To some javascript method DoSubmit(). What I tried is :

  • Invoke click on that submit button
  • Invoke submit on form ('form1').submit(), document.forms['form1'].submit()
  • jQuery forms with ('form1').AjaxSubmit();
  • Create jQuery AJAX

    $.ajax({                                                        
        type: "POST",
        url: $("#form1").attr("action"),
        data: $("#form1").serialize(),            
        success: function() {
            alert("epic win!!!1!1!")      
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("epic fail!")                                        
        }
    });
    

All those method created normal request (not AJAX), or they didn't work. So anyone know how I can do AJAX submit "Form", from JavaScript and strongly typed mechanism (public AcrionResult MyFormAction(FormModel model); ) will work?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about asp.net-mvc