When the modal opens automatically a textbox has a data or info. I want to save that to mysql before the modal closes or after it closes without using a submit button. Is there a way to do this using jquery i suppose?
Im using laravel, resource controller feature
here is my code with button
$('#student_form').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax({
url:"{{ route('ajaxdata.postdata') }}",
method:"POST",
data:form_data,
dataType:"json",
success:function(data)
{
if(data.error.length > 0)
{
var error_html = '';
for(var count = 0; count < data.error.length; count++)
{
error_html += '<div class="alert alert-danger">'+data.error[count]+'</div>';
}
$('#form_output').html(error_html);
}
else
{
$('#form_output').html(data.success);
$('#student_form')[0].reset();
$('#action').val('Add');
$('.modal-title').text('Add Data');
$('#button_action').val('insert');
$('#student_table').DataTable().ajax.reload();
}
}
})
});
});
you can do this by hooking up to the modal event in bootstrap.try this out,
$('#youModalId').on('hidden.bs.modal', function (e) {
// get the value from the input box
// make the ajax call here
})
for more information go to this link