-5

I have like 143 form fields (text, textarea and select) that I would like to send through an AJAX post request. Is there a way I can do this quick without manually add every field to the query?


Alright so I've set up thing like this:

jquery

$("#submitbtn").click(function(){
$.ajax({url: "check_data.php", data: $("#form").serialize(), success: function(result){
   alert(result);
}});

});

The form is declared like this:

<form class="pure-form" onsubmit="return false;" method="POST" id="form">

I tried also without the "return: false"

And the button as follow:

<button id="submitbtn" class="pure-button pure-button-primary">INSERT</button>

But it does not work, when I press the button I get no js or network activity whatsoever on the console, and nothing happens.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pistacchio
  • 445
  • 4
  • 15
  • 1
    You can serialize the form data. https://api.jquery.com/serialize/ – Jay Blanchard Oct 22 '15 at 12:07
  • 3
    Possible duplicate of [Attach all fields form a from to ajax request](http://stackoverflow.com/questions/20588272/attach-all-fields-form-a-from-to-ajax-request) – Naruto Oct 22 '15 at 12:20

1 Answers1

0

I solved it by using this:

$(function() {
 $("#form").on("submit", function(event) {
  event.preventDefault();
   
  $.ajax({
   url: "check_data.php",
   type: "POST",
   data: $(this).serialize(),
   success: function(d) {
    alert(d);
   }
  });
 });
});
Pistacchio
  • 445
  • 4
  • 15