当模式自动打开时,一个包含数据或信息的文本框。我想在模式关闭之前或关闭后将其保存到mysql,而不使用提交按钮。我想有没有办法使用jquery做到这一点?
我正在使用laravel,资源控制器功能
这是我的按钮代码
$('#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();
}
}
})
});
});
发布于 2019-04-05 13:01:05
您可以通过连接到bootstrap.try this out中的模式事件来实现这一点,
$('#youModalId').on('hidden.bs.modal', function (e) {
// get the value from the input box
// make the ajax call here
})
有关详细信息,请访问此link
https://stackoverflow.com/questions/55527890
复制相似问题