4

I don't know how can I specify .html() in back of my input field while sending data via ajax

I want $(Content) as a html formatted data but by using FromData() it seems not possible.

 
$("form#data").submit(function(e) {
  e.preventDefault();
  var formData = new FormData(this);
  var Content = document.getElementById("editor").innerHTML;
  $.ajax({
    url: 'php/videoUpload.php',
    type: 'POST',
    data: formData,
    Content: $(Content).html(), //Not working (Can't see the Content in my ajax request in console window)
    success: function(data) {},
    cache: false,
    contentType: false,
    processData: false
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id="data" method="post" enctype="multipart/form-data">
  <div class="form-group">
    <input type="text" class="form-control" name="title">
  </div>
  <div id="toolbar"></div>
  <div id="editor"></div>
  <input type="file" name="file" id="fileToUpload">
  <button type="submit" class="SubmitButton">Post</button>
</form>
sach jot
  • 570
  • 4
  • 16

1 Answers1

2

formData is what is actually being sent to the server. jQuery implements the content property but not the way you are expecting it. If you want to add the innerHTML of the editor div to the body of the request you need to add it to your formData object. A simple way to do this would be to just add

formData.editorContent = document.getElementById("editor").innerHTML;

under your call to new FormData

Adam H
  • 1,750
  • 1
  • 9
  • 24