1

I have updated this question to make it clearer:

I am sending the word "Über" as the value in a php header as a response to an ajax request like so:

header('title: ' . 'Über');

The word "Über" comes from the database with the columns set as utf8_general_ci and when I echo out the word from the database I see it correctly.

The problem occurs in javascript when I do:

var title = request.getHeader('title');

I then do:

console.log(title);

In Chrome the value of title is correct (Über), but in Safari and Firefox it is converted to "Ãber".

I think that the problem might be that I'm sending the value in the header rather than normal response string.

Any help much appreciated.

Rupert
  • 1,629
  • 11
  • 23
  • This is an encoding issue. Where does the `Ü` come from? It needs to be stored in the same encoding as the page you display. Most likely, you are using a single-byte encoding to display the page, but storing the `Ü` as a UTF-8 character. – Pekka May 09 '13 at 11:19
  • I have set. The whole title is set in the header in the response from the php. – Rupert May 09 '13 at 11:21
  • OK, but where does the `Ü` character come from? From the document? From a database? – Pekka May 09 '13 at 11:21
  • See [UTF-8 all the way through](http://stackoverflow.com/q/279170) – Pekka May 09 '13 at 11:22
  • The "Ü" character comes from the database. The columns are all set to utf8_general_ci. When I hard load the page, the title also has a "Ü" character and comes from the database and it works ok. It's just when I send the data from php to javascript in Safari when it goes wrong. – Rupert May 09 '13 at 11:45
  • That's likely a database connection encoding problem then. See the link above for how to set the right connection encoding – Pekka May 09 '13 at 11:48
  • I don't follow you. How is it a database connection encoding problem when it works fine all the time in Chrome but not in Safari? Php gets the correct data. I echo the browser title and I see the correct text. The problem occurs when I set the bowser title with js. – Rupert May 09 '13 at 11:54
  • 1
    I'm pretty sure that the problem is that you aren't allow raw unicode (at least as a token) in [HTTP headers](http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2). – Quentin May 09 '13 at 12:29
  • You're right. Hmm, odd. What Quentin says probably hits the nail on the head. Try `urlencode()` / `urldecode()`. If the problem persits with those, you probably have a database issue – Pekka May 09 '13 at 12:34

1 Answers1

0

Quentin was right. Sending raw unicode in the header caused this problem. I changed to a normal ajax request and it fixed things. Thanks everyone for your help.

Rupert
  • 1,629
  • 11
  • 23