使用 ajax 发送 ckeditor 的值,它只显示几行
send the values of ckeditor using ajax it diaplays only few lines
ckeditor 内容将完全进入 script.i 可以通过警报检查。
var ckpost=CKEDITOR.instances['content'].getData();
alert(ckpost);
$.ajax({
type: "POST",
url: "addpost.php",
data: "ckpost=" + ckpost,
success: function(msg){ }
});
在这个警报之后,我在 addpost.php 中使用 ajax.but 将 ckpost 的值发送到另一个页面,我只能得到这个 ckpost 的几行。
$post =$_POST['ckpost'];
echo $post;
这些代码在我的 addpost.php 中使用。我怎样才能使用 ajax 获得这些完整的值。
您的请求数据没有正确编码,您可以使用encodeURIComponent
$.ajax({
type: "POST",
url: "addpost.php",
data: "ckpost=" + encodeURIComponent(ckpost),
success: function(msg){ }
});
或者传递一个对象作为数据参数
$.ajax({
type: "POST",
url: "addpost.php",
data: {"ckpost": ckpost},
success: function(msg){ }
});
正确编码请求。
<script>
var ckpost=CKEDITOR.instances['content'].getData();
$.ajax({
type: "POST",
url: "addpost.php",
data: "ckpost=" + encodeURIComponent(ckpost),
success: function(msg){ }
});
</script>
addpost.php
<?php
$ckpost = decodeURIComponent($_POST['ckpost']);
.
.
?>
encodeURIComponent
encodeURIComponent escapes all characters except the following:
alphabetic, decimal digits, - _ . ! ~ * ' ( ). The
encodeURIComponent() function encodes a URI component. This function
encodes special characters. In addition, it encodes the following
characters: , / ? : @ & = + $ #
语法:
encodeURIComponent(str);
decodeURIComponent
The decodeURIComponent() function decodes a URI component.
语法:
decodeURIComponent(uri);
欲了解更多信息,encodeURIComponent & decodeURIComponent
ckeditor 内容将完全进入 script.i 可以通过警报检查。
var ckpost=CKEDITOR.instances['content'].getData();
alert(ckpost);
$.ajax({
type: "POST",
url: "addpost.php",
data: "ckpost=" + ckpost,
success: function(msg){ }
});
在这个警报之后,我在 addpost.php 中使用 ajax.but 将 ckpost 的值发送到另一个页面,我只能得到这个 ckpost 的几行。
$post =$_POST['ckpost'];
echo $post;
这些代码在我的 addpost.php 中使用。我怎样才能使用 ajax 获得这些完整的值。
您的请求数据没有正确编码,您可以使用encodeURIComponent
$.ajax({
type: "POST",
url: "addpost.php",
data: "ckpost=" + encodeURIComponent(ckpost),
success: function(msg){ }
});
或者传递一个对象作为数据参数
$.ajax({
type: "POST",
url: "addpost.php",
data: {"ckpost": ckpost},
success: function(msg){ }
});
正确编码请求。
<script>
var ckpost=CKEDITOR.instances['content'].getData();
$.ajax({
type: "POST",
url: "addpost.php",
data: "ckpost=" + encodeURIComponent(ckpost),
success: function(msg){ }
});
</script>
addpost.php
<?php
$ckpost = decodeURIComponent($_POST['ckpost']);
.
.
?>
encodeURIComponent
encodeURIComponent escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( ). The encodeURIComponent() function encodes a URI component. This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
语法:
encodeURIComponent(str);
decodeURIComponent
The decodeURIComponent() function decodes a URI component.
语法:
decodeURIComponent(uri);
欲了解更多信息,encodeURIComponent & decodeURIComponent