[英]Characters not saving correctly in database
I am not sure if this is because of jquery, mysql or php 我不确定这是因为jquery,mysql还是php
I have a basic AJAX call: 我有一个基本的AJAX呼叫:
$(document).on("click", "#save-edit", function(){
var id = $(this).closest("div.answer-section").attr("data-id");
$.ajax({
type: "post",
data: {
id: id,
answer: $("#edit-box").val()
},
url: "/process/edit",
dataType: "json",
success: function(data){
// display the data
}
});
});
and a basic SQL query: 和基本的SQL查询:
$sql = $pdo->prepare("update answers set answer = :answer where answer_id = :aid");
$sql->bindParam("answer", $_POST["answer"], PDO::PARAM_STR);
$sql->bindParam("aid", $_POST["id"], PDO::PARAM_INT);
$sql->execute();
The problem I am having is, it saves characters like this: é é
in the database as this é é
then displays é é
on the page, so what is causing this, the JQuery, or the MySQL or the PHP? 我遇到的问题是,这样可以节省这样的文字: é é
在数据库中,因为这é é
然后显示é é
的页面上,这样是什么原因造成这一点,JQuery的,或MySQL或PHP的? How can I fix it? 我该如何解决?
好吧,我找到了答案,一切都很好,只需要将其添加到HTML标头即可:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.