wawan Setiyawan wawan Setiyawan - 2 months ago 11
Javascript Question

Submit form with $.ajax when submit button is outside the form

i have multiple form, so i create a form with button submit outside form, this form

$("#buttonSubmit").click(function (event) {
if (confirm("Anda yakin akan Checkout ?")) {
var formData = new FormData("form#formData");
url: 'belanja/belanja_crud.php',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
dataType: 'json',
success: function (data) {
return false;

<form id='formData'>
<!-- input bla bla bla -->
<button id='buttonSubmit' type='button'>Submit</button>

how to get all input from form on above and submit with ajax ?


To get all data in the form in one instruction you can use .serialize()


    type: "POST",
    url: 'belanja/belanja_crud.php',
    data: $("#formData").serialize()
.done(function (data) {
    //do somthing
.fail(function (xhr, ajaxOptions, thrownError) {
    //do something

Or you can see this topic if you want it to JSON Format