带有特殊字符的PHP、AJAX、TINYmce POSTÆØÅ;不起作用
我在发帖时遇到了特殊字符æå的问题。 我在网上搜索过,找不到任何相关的东西 我的AJAX如下所示:带有特殊字符的PHP、AJAX、TINYmce POSTÆØÅ;不起作用,php,jquery,mysql,ajax,tinymce,Php,Jquery,Mysql,Ajax,Tinymce,我在发帖时遇到了特殊字符æå的问题。 我在网上搜索过,找不到任何相关的东西 我的AJAX如下所示: function savep(str){ // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Create some variables we need to send to our PHP file var url = "savep.php"; var text
function savep(str){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "savep.php";
var text = document.getElementById("myarea").value=tinyMCE.activeEditor.getContent();
var vars = "id="+str+"&text="+text;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState === 4 && hr.status === 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
// document.getElementById("status").innerHTML = "processing...";
document.getElementById("status").innerHTML = "<img src='../pics/process.gif' width='32' height='32'>";
}
<?php
include('../session/session.php');
if(isset($_POST['id'])&& !empty($_POST['text'])){
$id = $_POST['id'];
$cont = $_POST['text'];
error_log($cont);
$stmt = $conn->prepare("UPDATE pages SET content=:cont where id=:id");
$stmt->bindParam(':cont',$cont, PDO::PARAM_STR);
$stmt->bindParam(':id',$id, PDO::PARAM_INT);
$stmt->execute();
$pchange = $stmt->rowCount();
if($pchange > 0)
{
echo "<div class='alert alert-success' role='alert'>Adgangskoden er ændret</div>";
$conn = null;
} else
{
echo "<div class='alert alert-danger' role='alert'>Adagangskoden blev ikke ændret</div>";
$conn = null;
}
} else
{
echo "<div class='alert alert-danger' role='alert'>Det indstastede kodeord er forkert!</div>";
$conn = null;
}
?>
函数保存(str){
//创建XMLHttpRequest对象
var hr=新的XMLHttpRequest();
//创建一些我们需要发送到PHP文件的变量
var url=“savep.php”;
var text=document.getElementById(“myarea”).value=tinyMCE.activeEditor.getContent();
var vars=“id=“+str+”&text=“+text;
hr.open(“POST”,url,true);
//设置用于在请求中发送url编码变量的内容类型标头信息
hr.setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded;字符集=UTF-8”);
//访问XMLHttpRequest对象的onreadystatechange事件
hr.onreadystatechange=函数(){
如果(hr.readyState==4&&hr.status==200){
var return_data=hr.responseText;
document.getElementById(“status”).innerHTML=返回数据;
}
}
//立即将数据发送到PHP…并等待更新status div的响应
hr.send(vars);//实际执行请求
//document.getElementById(“status”).innerHTML=“处理…”;
document.getElementById(“状态”).innerHTML=“”;
}
我发现,当它抛出JAVA时,它不会发布特殊字符
我的PHP如下所示:
function savep(str){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "savep.php";
var text = document.getElementById("myarea").value=tinyMCE.activeEditor.getContent();
var vars = "id="+str+"&text="+text;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState === 4 && hr.status === 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
// document.getElementById("status").innerHTML = "processing...";
document.getElementById("status").innerHTML = "<img src='../pics/process.gif' width='32' height='32'>";
}
<?php
include('../session/session.php');
if(isset($_POST['id'])&& !empty($_POST['text'])){
$id = $_POST['id'];
$cont = $_POST['text'];
error_log($cont);
$stmt = $conn->prepare("UPDATE pages SET content=:cont where id=:id");
$stmt->bindParam(':cont',$cont, PDO::PARAM_STR);
$stmt->bindParam(':id',$id, PDO::PARAM_INT);
$stmt->execute();
$pchange = $stmt->rowCount();
if($pchange > 0)
{
echo "<div class='alert alert-success' role='alert'>Adgangskoden er ændret</div>";
$conn = null;
} else
{
echo "<div class='alert alert-danger' role='alert'>Adagangskoden blev ikke ændret</div>";
$conn = null;
}
} else
{
echo "<div class='alert alert-danger' role='alert'>Det indstastede kodeord er forkert!</div>";
$conn = null;
}
?>
您可以在保存编辑器内容之前将字符重新编码为html条目您可以在保存编辑器内容之前将字符重新编码为html条目