Problem with accents in . serialize()

Asked

Viewed 1,163 times

0

The .serialize(); takes all form information, but with different accents

ex: LOAF stays P%C3%83O , when I test the app on localhost the accents work right but when hospedo gets like this BREAD ???

I made this example

 <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 ); });

On the.log() console is

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 serializo becomes strange, I believe it is the same reason that my app is giving accentuation problem.

To avoid problem in the use site <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > on all pages.

There is a way to code when serializing?

  • Straw%C3%A7%C3%A3o&str2=F%C3%A1bio is correct in UTF-8. The problem seems to be when showing the data. Remember to set the charset on the goal too: <meta charset="utf-8"> to be sure of what is happening.

  • @Bacco - That’s right. It is only necessary to treat this string. in PHP can be done with utf8_decode().

  • I am using Javaservlets and in Insert the letter Á stays  â â

  • make sure you are not decoding the string twice in the same code by mistake.

1 answer

1


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

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

As for being using Javaservlets, maybe that answer Stack Overflow help you.

  • Thank you. I’ve got it on Servlet Response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); and it works on the localhost but not on the hosting!? whatever it is

  • This is another five hundred and, for that, perhaps it would justify creating a new topic. However, maybe the same would be closed by decontextualisation.

  • you’re right. thank you

  • If the answer helped, don’t forget to at least mark it as much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.