开发者

How do i fetch a single value from serialize()

I have a form and i fetch the values of form u开发者_如何转开发sing jQuery .serialize(); for example to fetch the form data i use the following.

var formData = $('form').serialize();

now the variable formData holds the following value.

subcategoryname=aaaa&prefix=AA&categoryid=1

from the above string i want to fetch only the value of categoryid i.e 1 here, how do i do it using jQuery?


I think you should use .serializeArray() to make it as an object which makes it much easier to access.


you can parse it by splitting the "&" and subsplit each by "="

or take this plugin: http://plugins.jquery.com/project/deserialize

Maybe you should access the field before serializing, then you wont need to deSerialize


Would it not be easier to use:

$('input[name=categoryid]').val();

Or is this not an option?


if you only need one value of your form, why use .serialize() ?
You could use standard selectors


You can access each value using this method :

var firstValue = formData[0].value;

var secondValue = formData[1].value;

var thirdValue = formData[2].value;

. . . etc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜