A
A
alexeygavrilovs2020-04-17 15:12:08
JavaScript
alexeygavrilovs, 2020-04-17 15:12:08

How to add button value to ajax request?

Good afternoon, there is a code that passes values ​​from the form, there are also two buttons, one passes the True value, the other is false, how to additionally pass this value to the ajax request
here is the code

<script>
        $( document ).ready(function() {
            $("button").click(function(){
                    sendAjaxForm('ajax_form', btn);
                    return false;
                }
            );
        });
        function sendAjaxForm(ajax_form, btn) {

            $.ajax({
                url:     '/getvote',
                type:     "POST",
                dataType: "json",
                data:
                    $("#"+ajax_form).serialize(),

                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                success: function (data) {

                },
                error: function (er) {

                }
            });
        }
    </script>

The value from the form is passed, from the button - no.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2020-04-17
@alexeygavrilovs

Add a hidden field to the form. When clicking on buttons, set this value to true or false. Therefore, when you submit the sendAjaxForm form, your hidden field will also be submitted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question