Serializing form inputs with jquery
I have a form with many hidden divs and a select for showing a single div.
But when submitting the data to the server, all data is sended and some values are lost (fields with the same name in different divs).
This is a scenario example:
<form>
<select>
<option value="ga">GA</option>
<option value="om">OM</option>
</select>
<div class="ga">
<input type="text" name="a_field" />
开发者_如何转开发 <input type="text" name="a_field_2" />
...code
</div>
<div class="om">
<input type="text" name="a_field_2" />
<input type="text" name="a_field_100" />
...code
</div>
</form>
How can I do for only serialize the div I want?
My first approach was remove the hidden divs in the beforeSerialize method from ajaxForm, but now I need to serialize the values when clicking another links to make another calls (and not to submitting the form).
Thanks in advance
you can do it manually:
var serial = new Array();
var i = 0;
$('.om input').each( function(){
serial[i++] = $(this).attr('name')[0]+'='+$(this).html()[0];
});
serial.join('&');
精彩评论