Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access jQuery serialized data?

How can I access the data that has been 'serialized' using the jQuery function?

var test = $("form").serialize();

I have this data...

url=hello+1&title=hello+1&content=abc

How can I get the value of 'url'? - I tried this...

console.log(test.url); 

But I get undefined - I want to get the result as "hello+1"

like image 994
Run Avatar asked Oct 20 '13 16:10

Run


1 Answers

The serialize method only creates a URL encoded string from a form, but this is a string, i.e you can not get the value of url or any other value. To do so you need to parse back the string into an object. You can check library out: https://github.com/kflorence/jquery-deserialize

However it would be best if you simply select the field containing that value and get it from there, i.e.

jQuery('input[name="url"]').val();

or if you have an id or class on that field, you can use it as a selector.

P.S. The value of url is "hello 1" the + is just how spaces are encoded in query strings.

like image 167
Tsanyo Tsanev Avatar answered Nov 05 '22 17:11

Tsanyo Tsanev