javascript - encoding issue on form.serialize(); Some specials character displaying as ASCII code - Stack Overflow

I am having a problem with special character in javascript.I have a form with a input text that has th

I am having a problem with special character in javascript. I have a form with a input text that has the following string:

10/10/2010

after a form.serialize(); I get this string as

10%2F10%2F2010

The '/' character is converted to its ASCII code %2F.

I would be able to convert that using String.fromCharCode(ascii_code) but I have many inputs in my form so these string is somenthing like:

var=14&var=10%2F10%2F2010&var=10%2F10%2F2010&var=10%2F10%2F2010

Just an example to state that I would have to go through this string ("manually") and find those value and convert it.

Is there any easy way to perform that conversion? Strange thing because I did not have that problem before, I am not sure why this is happening now.

I am having a problem with special character in javascript. I have a form with a input text that has the following string:

10/10/2010

after a form.serialize(); I get this string as

10%2F10%2F2010

The '/' character is converted to its ASCII code %2F.

I would be able to convert that using String.fromCharCode(ascii_code) but I have many inputs in my form so these string is somenthing like:

var=14&var=10%2F10%2F2010&var=10%2F10%2F2010&var=10%2F10%2F2010

Just an example to state that I would have to go through this string ("manually") and find those value and convert it.

Is there any easy way to perform that conversion? Strange thing because I did not have that problem before, I am not sure why this is happening now.

Share Improve this question asked Jan 31, 2013 at 16:07 Guilherme LongoGuilherme Longo 2,3087 gold badges47 silver badges65 bronze badges 1
  • 1 decodeURIComponent("10%2F10%2F2010") – Yury Tarabanko Commented Jan 31, 2013 at 16:10
Add a ment  | 

1 Answer 1

Reset to default 6

I happens that way because that's how it's meant to be:

The .serialize() method creates a text string in standard URL-encoded notation. It operates on a jQuery object representing a set of form elements.

As far as I know, there's no native jQuery function to unserialize but your post suggests you already got that and are only stuck in the URL-encoded strings:

decodeURIComponent(encodedURI)
Decodes a Uniform Resource Identifier (URI) ponent previously created by encodeURIComponent or by a similar routine.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745109133a4611740.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信