doujuegai8830 2019-07-03 09:55
浏览 225

如何通过ajax将summernote编辑器中的数据发送到php文件?

I am trying to capture the data from a summernote editor and sending it to a php file via ajax.

I am using the load() to pass some set of parameters to a php file which works perfectly; but I got to understand that the summernote data is made up of HMTL tags and it will take so much effort validating the summernote data for transport. Instead I decided to make another ajax call using the $.ajax(). Each time I send the data, the load() ajax call works but the $.ajax() don't, instead I get an error stating -

Uncaught TypeError: Illegal invocation
    at i (jquery.min.js:2)
    at jt (jquery.min.js:2)
    at Function.w.param (jquery.min.js:2)
    at Function.ajax (jquery.min.js:2)
    at HTMLButtonElement.<anonymous> (<anonymous>:88:58)
    at HTMLButtonElement.dispatch (jquery.min.js:2)
    at HTMLButtonElement.y.handle (jquery.min.js:2)

Below is my code

    $(document).ready(function() {
      $("#summernote").summernote();
      //Comment
      var commentForm = document.getElementById("commentForm");
      var domID = "#taskPro" + jobID;

      $(domID).html('<div class="progress-bar progress-bar-striped progress-bar-animated bg-danger" style="width:100%;">Sending Report</div>');
      $(domID).load("../../../config/actions.php?cN=" + customerNumber + "&date=" + date + "&fullName=" + newString7 + "&address=" + newString8 + "&landMark=" + newString9 + "&commet=" + comment + "&complextion=" + complextion + "&type1=" + type1 + "&type2=" + type2 + "&color=" + color + "&xOwner=" + newString0 + "&areaProfile=" + newString1 + "&ifn=" + newString2 + "&ixOwner=" + newString3 + "&iAddress=" + newString4 + "&telephone=" + newString5 + "&requestType=" + newString6 + "&jobID=" + jobID + "&gpsCoords=" + gpsCoords + "&submitReport=1");
      //Post Comment
      $.ajax({
        url: "../testAction.php",
        type: "POST",
        data: new FormData(commentForm),
        contentType: "text/plain"
      });
    });
    <form method="post" action="" id="commentForm">
      <textarea class="form-control" name="comment" id="summernote"><p>Comment: Should contain Comment, Verification Status Description, Building deatails. Also upload images where neccessary</p></textarea>
    </form>

    <script>
    </script>

I expect to submit the data captured from the summernote editor to the database using the mysqli_real_escape_string()

</div>
  • 写回答

2条回答 默认 最新

  • drelgkxl93433 2019-07-03 10:28
    关注

    You may try below code:

      $.ajax({
                type: "POST",
                url: "../testAction.php",
                data : { summernote : $("#summernote").summernote("code"); },
                success: function(response) {
                    // response 
                    // console.log(response,"response");
                },
                error: function(errResponse) {
                    // alert(errResponse)
                    // console.log("errResponse", errResponse);
                }
            })
    
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行