Post Entire Form or Multiple Items to MVC 4 Controller via jQuery.Ajax -serialize()

1066
Views
1
Answers

How to post entire form or multiple fields of the form using jQuery ajax ?

edit | flag
Mad Maddy
Asked on: Jan 28, 2012 at 7:14AM

1 Answers

107
10
107

Yes, you can use .Serialize() function.

 function PostForm() {
        $
.ajax({
            url
: "/Home/myaction",
            type
: "POST",
            data
: $('#myform').serialize() ,
         success
: function (result) {alert('sucess');}
       
});
   
};

The serialize function basically gets all the elements into jquery format.
If you want to add some other elements which are not in the form you can also add it like..

function PostForm() {
    $
.ajax({
        url
: "/Home/myaction",
        type
: "POST",
        data
: $('#myform').serialize() + "&" + $('#otherParams').serialize(),
        success
: function (result) {alert('sucess');}
   
});
};
edit | flag
Askamoeba Member
Answered on: Jan 28, 2012 at 7:28AM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags