0

Well, I have tried a lot of JS codes to post one form with multiple data [2 Files & 1 textarea] and they didn't work well.

But How to send non-empty form data to PHP using AJAX?

<form method="post" enctype="multipart/form-data">
  <textarea id="acas"></textarea>
  <input id="uimage" type="file" name="image" accept=".png,.jpg,.gif"/>
  <input id="uaudio" type="file" name="audio" accept=".mp3"/>
  <input id="armes" style="display: none;" name="send" type="submit"/>
</form>

By default I use this JS code below to submit form, But it reloads page:

$("#acas").on('keydown', function(e) {
    if (e.key == "Enter") { 
      if (e.shiftKey) {

      } else {
        e.preventDefault();
        $("#armes").click();
      }
    }
});
Adharsh M
  • 2,773
  • 2
  • 20
  • 33
I_I
  • 13
  • 1
  • 6
  • Click function submit the form. That's why its reloading.! You need to write the ajax function. https://stackoverflow.com/questions/23980733/jquery-ajax-file-upload-php Refer this to know how to file submit with ajax – Adharsh M Apr 06 '19 at 05:16

1 Answers1

0

Use this code

  $(document).on('submit', 'form', function (e)
    {
        var form = new FormData(this);
        jQuery.ajax({
            url: "",
            method: 'POST',
            processData: false,
            contentType: false,
            dataType: "json",
            data: form,
            success: function (response)
            {
             }
        });
        return false;
      });
Sandeep K.
  • 759
  • 6
  • 18