Before HTML5 there were a bunch of techniques and plugins for jQuery to implement AJAX file uploads. HTML5 introduces FormData class that can simplify file uploads.
In this post, find how to serialize ASP.NET web form using jQuery. JQuery provides a very useful function jQuery.serialize() which encodes a set of form elements as a string. What is serialize and why do we need? Serialize is a way to combine your form values and create a single string which then can be used to send to server for ajax request.
Thant's it. You fon't need any plugins, flash or iframe tricks. It just works. There is a couple tricks here that makes this code to work the way we expect:
![Jquery Ajax Serialize Jquery Ajax Serialize](http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/3d39b4/working-with-html-beginform-and-ajax-beginform-in-mvc-3/Images/MVC1.jpg)
- When we create instance of FormData we pass form[0] instead form. It's mean actual form element, but not jQuery selector.
- Instead of defining
contentType
we just passfalse
. This tells jQuery to not addContent-Type
header to the request. - We set
processData
tofalse
, so, jQuery will not convert ourdata
value (which in stance ofFormData
) to a string.
There is very helpful HTML5Rocks article
![Jquery Ajax Serialize Jquery Ajax Serialize](/uploads/1/2/5/7/125754167/836734013.png)
Happy coding!