D
D
Dmitry2015-10-03 20:58:16
PHP
Dmitry, 2015-10-03 20:58:16

Why is encoded text coming from an AJAX POST request in PHP?

I send the request like this:

$.post("ajax.php",
        {
          act: "avatar",  
          persname: $("#persname").val()
        },
        onAjaxSuccess
      );


I process on the PHP side I tried to process persname encodeURIComponent, and on the PHP side to decode the string (urldecode)... I still get a string like \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 And I work locally on Ubuntu - everything is fine . I'm uploading to the server.. I'm getting a problem with the encoding of the text in the request. How to fix?
htmlspecialchars($_POST['persname']);


Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry, 2015-10-03
@falcon_sapsan

Problem solved.
Locally, the database was created through phpmyadmin - and UTF-8 encoding was selected.
When transferred to the server, the database was created manually from the console, without explicitly specifying the base encoding, so the database was in latin encoding ...
Existing tables were imported into the created database, which were in the correct utf8_general_ci encoding.
Despite the fact that the tables were in the correct encoding, the encoding broke.

V
veydlin, 2015-10-03
@veydlin

Maybe the encodings of the page and the script are different?
Did you know that when sending $.post all text is automatically encoded in UTF-8? Maybe this is the issue?

I
Ivan, 2015-10-03
@LiguidCool

.For some reason, it seems to me that your PHP script encoding is incorrect. Standard UTF8.

E
Evgeny Svirsky, 2015-10-03
@e_svirsky

try setting on hosting via htaccess parameter:
php_value default_charset UTF-8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question