0

I've got an application that load pages and submit form using ajax. The whole form submission application-wide is done using the following snippet:

/* Récupére tous les form avec pour class iframe-form et les charge dans l'iframe */
$('.iframe-form').unbind('submit').submit(function (e) {
    var data = $(this).serialize();

    e.preventDefault();
    if (!$(this).attr('action')) {
        console.error('Form action undefined');
        return;
    }
    loadPage('#main_frame', 'POST', $(this).attr('action'), data);
});

The problem arise when we use an It look like the name and the value of the clicked button isn't taken into account by the serialize() function.

It seems logic to me because the submit event doesn't know what caused the submission.

However, I need to make it work and I'm currently struggling to find a way to incorporate such edge case into this routine. I seems straight forward at first but I'm unable to find an elegant solution for now.

Can someone recommend a way of doing this without breaking the whole application?

Atrakeur
  • 4,126
  • 3
  • 17
  • 22
  • Instead of binding the form's `submit` event, you can bind the submit button's `click` event. Then you can get the button's name and value and append them to `data`. – Barmar Apr 29 '16 at 15:48
  • 1
    Related: http://stackoverflow.com/questions/2066162/how-can-i-get-the-button-that-caused-the-submit-from-the-form-submit-event – Barmar Apr 29 '16 at 15:48

0 Answers0