【问题标题】:Post Summernote code through Ajax to PHP and then insert into database通过 Ajax 将 Summernote 代码发布到 PHP,然后插入数据库
【发布时间】:2019-06-30 03:29:49
【问题描述】:

我有一个带有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 只会向上跳转,然后跳过其余的标签和文本。

【问题讨论】:

    标签: javascript php ajax summernote


    【解决方案1】:

    如图所示更新

    var dataString = 'desc=' + description; 更新为var dataString = {desc: description};

    【讨论】:

    • 我稍后会试一试,会更新结果。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 2014-01-13
    • 2019-11-13
    • 2019-05-27
    • 1970-01-01
    相关资源
    最近更新 更多