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 ?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.