簡體   English   中英

如何通過ajax從summernote編輯器中將數據發送到php文件?

[英]How can I send data from a summernote editor via ajax to a php file?

我正在嘗試從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編輯器捕獲的數據提交到數據庫。

您可以嘗試以下代碼:

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

您需要正確解析FormData值。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM