Sending submissions with AJAX

Accepting file uploads with AJAX is not supported by some browsers like Internet Explorer, but you can still do it with Getform. Paste the following AJAX code before your body tag:

<script>
   $(function(){
       $("#ajaxForm").submit(function(e){
           e.preventDefault();
           var action = $(this).attr("action");
           $.ajax({
               type: "POST",
               url: action,
               crossDomain: true,
               data: new FormData(this),
               dataType: "json",
               contentType: 'multipart/form-data',
               processData: false,
               contentType: false,
               success: function(response){
                 if(response.status == "success"){
                   alert("We received your submission, thank you!");
                 }else{
                   alert("An error occured.");
               }
             }
           });
         });
       });

</script>

Note: You should add enctype="multipart/formdata" as in the regular case.

After that you can add class="ajaxForm" to your HTML form to finish the setup like this:

<form class="ajaxForm" action="https://getform.io/f/{your-endpoint}" method="POST" enctype="multipart/form-data">

    <input type="text" name="name" id=”name”>
    <input type="email" name="email" id=”email”>
    <input type="file" name="file">
    <button type="submit">Send</button>

</form>

That's it! You can also accept files for your form submissions using AJAX.