0

How to set utf-8 for ajax post requests ?

i use this code for ajax post requests

    $.ajax({
                url: 'test.php',
                dataType: 'text',
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,                         
                type: 'post',
                success: function(php_script_response){
                $('#files_attachments_list_display').append(php_script_response);
            }

In test.php, I tried to insert data into db , ok it's insert success.

but char that insert not utf-8. How can i do to set utf-8 on ajax post requests ?

1 Answers1

0

You JS uses the same charset your webpage uses. So add this in your <head>:

<meta charset="utf-8">

Then, you need to interpret the message at your server and read as UTF-8.


Sorry, didn't read your question clearly. You have to set the database server field to store string as utf-8.

If you are using MySQL:

Please read this: SET NAMES utf8 in MySQL?

and this: How to make MySQL handle UTF-8 properly

Community
  • 1
  • 1
Daniel Cheung
  • 4,779
  • 1
  • 30
  • 63