Submitting a jQuery ajax form with two submit buttons

前端 未结 8 1051
花落未央
花落未央 2020-12-05 07:31

I have a form that looks like this:

8条回答
  •  生来不讨喜
    2020-12-05 08:00

    Based on Emmett's answer, my ideal fix for this was just to kill the form's submit with Javascript itself, like this:

    $(".vote_form").submit(function() { return false; });
    

    And that totally worked.

    For completeness, some of my JS code in the original post need a little love. For example, the way I was adding to the serialize function didn't seem to work. This did:

        $form.serialize() + "&submit="+ $(this).attr("value")
    

    Here's my entire jQuery code:

    $(".vote_form").submit(function() { return false; });
    $(".vote_up, .vote_down").click(function(event) {
        $form = $(this).parent("form");
        $.post($form.attr("action"), $form.serialize() + "&submit="+ $(this).attr("value"), function(data) {
            // do something with response (data)
        });
    });
    

提交回复
热议问题