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

时间:2019-07-03 09:55:36

标签: php jquery summernote jquery-ajaxq

我正在尝试从summernote编辑器中捕获数据,并通过ajax将其发送到php文件中。

我正在使用load()将一些参数集传递到一个完美运行的php文件;但我必须了解,summernote数据由HMTL标签组成,并且需要花费大量精力来验证summernote数据以进行运输。相反,我决定使用$ .ajax()进行另一个ajax调用。每次发送数据时,load()ajax调用均有效,但$ .ajax()无效,相反,我收到一条错误消息,指出-

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)

下面是我的代码

    $(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>

我希望使用mysqli_real_escape_string()从summernote编辑器捕获的数据提交到数据库

2 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

  $.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);
            }
        })

答案 1 :(得分:0)

您需要正确解析FormData值。

data: new FormData($('#commentForm')[0]),
contentType: false,
processData: false