Answer the question
In order to leave comments, you need to log in
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>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question