Posting and returning data using jquery corrupts å ä ö

This is a question with a lot of information on the net. However, I have not decided this.

I have a dynamically loaded form on a web page. I am sending it using jquery $ .post. My page is intended for Swedes, so it needs to work with åäö.

When sending data to the server, it will load the data back into the new table. The returned å ä ö is damaged. Example åååäääööö = à ¥ à ¥ à ¥ äääööö

Server side - php. I encode all pages that return content to the browser as follows:

<?php header('Content-type: text/html; charset=ISO-8859-1'); ?> 

I tried utf8_encode and utf8_decode on the server side. Actually no difference.

And I tried this: encodeURIComponent ($ (this) .serialize ()), where $ (this) is the form to submit. Of course, this does not work, and I do not know how to encode an object like $ (this).

I thought this is what a lot of people do, but it doesn’t seem like a standard solution.

Therefore, I need help on how I can submit the form using javascript / jquery / etc. and handle it on the server side, returning it, and å ä ö looks as it should. This is perfectly normal if the server receives utf8. Should the principle use only UTF8, and then the problem is solved? There seems to be a different solution.

+6
source share
1 answer

AJAX uses UTF-8 encoding. If your data is not in UTF-8 format (for example, Windows 1251 or ISO-8859-1), you will have problems.

Specifying a different encoding scheme in the header will not convert your data to UTF-8. He simply tells the client what to expect.

My motto is: UTF-8 from end to end or die!

+4
source

Source: https://habr.com/ru/post/895790/


All Articles