Problem with accents in .serialize ()

0
The .serialize (); takes all information from the form, but with different accentuation

ex: BREAD is P% C3% 83O , when I test the app on localhost the accents work fine but when hosting stays like this Bread

strong> ???

I made this exmplo

 <form name='meuForm' method='post' action='action' id='formStr'>
   <input type='text'   name='str1' value='palhação' id='str1'  />
   <input type='text'   name='str2' value='Fábio'    id='str2' />  
   <input type='submit' id='teste'  valiue='testar' />  </form>
$( "form" ).on( "submit", function( e ) {  e.preventDefault(); var str1 = $('#str1').val();    var formSerializado = $(this).serialize();  console.log( 'str1 = '+str1+', formSerializado = '+ formSerializado ); });

In console.log () it gets

str1 = palhação, formSerializado = str1=palha%C3%A7%C3%A3o&str2=F%C3%A1bio

And I would like to understand why when I have the value of var str1 the value is right and when serializes it gets weird, I think it's the same reason my app is giving accent problem.

To avoid problem with site use <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > on every page.

Is there a way to encode when serializing?

    
asked by anonymous 08.09.2014 / 19:34

1 answer

1

According to the jQuery.serialize () manual, a UTF-8 string is created in the URL-Encoding pattern, also known as Percentage Encoding of all "Successful controls of the form.

It's not that your output is wrong, it's just different from what you expected. It remains to deal with the server-side language.

As for being using JavaServlets, maybe this answer from the English Stack Overflow helps you.

    
08.09.2014 / 19:51