DUG
DUG

Reputation: 329

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

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

Upvotes: 0

Views: 2208

Answers (2)

Rotimi
Rotimi

Reputation: 4825

You need to parse the FormData value properly.

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

Upvotes: 0

Shivani Sonagara
Shivani Sonagara

Reputation: 1307

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

Upvotes: 0

Related Questions