jQuery serializeArray doesn’t include the submit button that was clicked

Is [there] another method that DOESN’T exclude the activated button in a serialization?

There is not, the behavior is based on the submit event of the <form>, not of a button, e.g. hitting enter or calling .submit() in JavaScript. You’re mixing 2 concepts here, a .serialize() or .serializeArray() may or may not have anything to do with a button click – it’s just a separate event altogether, they’re not connected. These methods are at a higher level than that: you can serialize a form (or a subset of it) at any time for any reason.

You can however add the submit name/value pair like a normal form submitting from that button would, if you’re submitting from a button for example:

$("#mySubmit").click(function() {
  var formData = $(this).closest('form').serializeArray();
  formData.push({ name: this.name, value: this.value });
  //now use formData, it includes the submit button
});

Leave a Comment