2

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

$("#buttonSubmit").click(function (event) {
            event.preventDefault();
            if (confirm("Anda yakin akan Checkout ?")) {
                var formData = new FormData("form#formData");
                $(".loader").show();
                $.ajax({
                    url: 'belanja/belanja_crud.php',
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    dataType: 'json',
                    success: function (data) {
                       //console.log(data);
                    }
                });
            }
            return false;
        });
<form id='formData'>
  <!-- input bla bla bla -->
  </form>
<button id='buttonSubmit' type='button'>Submit</button>

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

Aroniaina
  • 1,252
  • 13
  • 31
wawan Setiyawan
  • 371
  • 7
  • 21

1 Answers1

3

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

E.g

$.ajax({
    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

Community
  • 1
  • 1
Aroniaina
  • 1,252
  • 13
  • 31