jquery's Serialize () method, which can serialize a form item, is a handy feature, but in practice it finds the following problems:
For example:
< textarea name= "content" >ABC 123 </textarea >
then after executing the serialize () method, the resulting string is abc+123;
that is, the serialization method of jquery escapes the space and translates it into a + sign.
part of the code for the Serialize method in jquery is as follows:
//.................
//.................
return S.join ("&"). Replace (//g, "+"); Replace the space with the + sign
after testing, the Serialize () method escapes the true "+" number by%2b, so you can rest assured that the result of serialize () is replaced with a symbol.
Example:
< textarea name= "content" >ABC + 123 + 456 </textarea >
jquery Code:
var a= $ (' $frm 1 '). Serialize ();//serialization, by default calls encodeURIComponent () to encode
alert (a);//content=abc+++123+++456
var b = a.replace (/\+/g, ""); G means to replace all eligible in the entire string
B = decodeuricomponent (b); Decode the content after the serialize
alert (b);//CONTENT=ABC + 123 + 456
at this point, the problem is solved.
Serialize method for jquery How to convert a space to + number solution