Ali
Ali

Reputation: 7483

Accentuated characters look funny in html passed in ajax call

I've run into issues here I notice that some accentuated characters if I try to pass them as value sin an ajax call they end up all funny LIke for example:

Adana Şakirpaşa

turns into

Adana %u015Eakirpa%u015Fa

WHats wrong here :(

EDIT==================

The problem is that once the characters are recieved by my php script on the backend they are all messed up by then! What should I do :(

Upvotes: 0

Views: 240

Answers (2)

VolkerK
VolkerK

Reputation: 96159

Java/ECMAscript parses \uxxxxxx sequences but not %u... in the source text.
see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf

You can convert the transport form with the javascript function unescape()
e.g.

<html>
  <head><title>...</title>
    </script>
  </head>
  <body>
    <p id="output"></p>
    <script type="text/javascript">
      var x = 'Adana %u015Eakirpa%u015Fa';
      document.getElementById("output").innerHTML = unescape(x);
    </script>
  </body>
</html>

shows

Adana Şakirpaşa

But you might consider to store and send it as "plain" utf-8 characters server-side.

Upvotes: 1

jeroen
jeroen

Reputation: 91734

I have run into the same problem and have used utf8_encode() on the data in the php script that was called using ajax to solve it. I think you can also use htmlentities().

Upvotes: 2

Related Questions