我有这个jQuery AJAX
函数,它从 a 中检索数据CKEDITOR text_area
并将其发送AJAX
到.php
文件:
function saveEmailData(){
var text_body = encodeURIComponent(CKEDITOR.instances.text_body.getData());
$.ajax({
url: 'al_ajax.php',
cache: false,
data: {area: text_body, use: 'savemaildata'},
type: 'POST',
success: function(result){
alert(result);
},
error: function(result){
alert('Error');
},
});
}
PHP:
$area = $link->real_escape_string($_POST['area']);
$insert_query = $link->query("INSERT INTO ALLARME_EMAIL_TEXT (area)
VALUES ('$area')
ON DUPLICATE KEY UPDATE
area = '$area'
")
or die('Error.');
if($insert_query){
echo 'OK!';
}
问题是使用jQuery AJAX
,我将在数据库%20
上使用正常javascript function
,这不会发生:我总是使用。为什么?
function saveEmailData(){
var text_body = encodeURIComponent(CKEDITOR.instances.text_body.getData());
if(window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
alert(xmlhttp.responseText);
}
}
xmlhttp.open("POST","al_ajax.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("area="+text_body);
}