我有一个带有 summernote 编辑器的页面,当用户提交该页面时,我通过 jquery 从编辑器中检索代码,然后将其发送到一个 php 页面,该页面随后将 html 插入到数据库中。在我将它发送到 php 页面之前,我从编辑器中检索到的 html 是正确的,但是一旦它到达 php 页面,大部分 html 就被剥离并且不完整。
这是我的夏令营
<div class="summernote" id="decription" name="description"></div>
$('.summernote').summernote({
dialogsInBody: true,
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['height', ['height']],
['undo', ['undo']],
['redo', ['redo']],
['help', ['help']]
],
placeholder: 'Describe the business here',
tabsize: 2,
height: 200
});
$('.dropdown-toggle').dropdown()
这是我在用户提交页面后从编辑器获取代码的方式
var description = $("#decription").summernote('code');
然后我将此描述发布到我的 php 页面以将数据插入数据库
var dataString = 'desc=' + description;
alert(dataString);
$.ajax({
type: "POST",
url: "../scripts/add/addpro.php",
data: dataString,
cache: false,
success: function(html) {
alert(html);
}
});
我在发帖前做一个提醒,以确保发送到 php 的代码是编辑器中的所有代码(仅用于测试),这始终是正确和完整的,发送到 php 的代码是编辑器中的所有代码。
在我的 addpro.php 页面中,我执行以下操作
$description = $_POST['desc'];
echo $description;
由 php 回显的 html 代码不完整且被剥离。例如,每当 html 代码中有一个逗号 (,) 时,php 只会跳到那个逗号,然后跳过其余的标签和文本。
最佳答案
如图所示进行更新
将 var dataString = 'desc=' + description;
更新为 var dataString = {desc: description};
关于javascript - 通过 Ajax 将 Summernote 代码发布到 PHP,然后插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54549212/