Javascript 为什么单击“添加区域”按钮时我的模式未关闭
单击“添加区域”按钮,我的模式应关闭,但它不工作。一切看起来都很好,但我找不到错误Javascript 为什么单击“添加区域”按钮时我的模式未关闭,javascript,php,ajax,laravel,Javascript,Php,Ajax,Laravel,单击“添加区域”按钮,我的模式应关闭,但它不工作。一切看起来都很好,但我找不到错误id=“category popup”应通过$(“#category popup”)关闭模式。模式('hide')但它不工作有人能帮我吗 <div class="modal fade" id="category-popup" tabindex="-1" role="dialog" aria-labelledby="category- popup" aria-hidden="true">
id=“category popup”
应通过$(“#category popup”)关闭模式。模式('hide')代码>但它不工作有人能帮我吗
<div class="modal fade" id="category-popup" tabindex="-1" role="dialog" aria-labelledby="category-
popup" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add Area</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post" action="{{ route("save.area.ajax") }}" class="category-form">
{{ csrf_field() }}
<div class="form-group">
<label>Area Name</label>
<input type="text" name="name" class="form-control old-category" required="">
</div>
<div class="form-group">
<button type="button" class="btn btn-primary btn-block add-area-submit-btn">Add
Area</button>
</div>
</form>
</div>
</div>
</div>
</div>
隐藏模式的语法是正确的,但请确保$.ajax请求成功。尝试在$.ajax success中执行console.log()。或者在ajax中添加错误,以便了解错误
$.ajax({
type: 'post',
data: $('.category-form').serialize(),
url: $('.category-form').attr('action'),
success: function(res) {
console.log("ajax request success");
$("#area-select").html(res);
$("#category-popup").modal('hide');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("ajax request failed: " + errorThrown);
}
});
嗯,奇怪,你确定你正确地包含了jQuery吗?您能展示一下包含的脚本吗?
jQuery应该是这样的:
在JavaScript中,一个错误会导致整个脚本崩溃。没有jQuery,您的“模态”操作将无法工作。我认为这就是你的脚本不起作用的原因。
检查选项字段中cnsole it submit区域中的错误,但未关闭不确定我是否理解,但您的最后一行$(“#类别弹出窗口”)。model('hide')。据我所知,modal不是公认的js属性。如果您只是想在#catagory popup上使用jQuery.hide()方法,只需将$(#category popup”).hide()放进去即可@他所做的是正确的。modal来自bootstrap.js阅读以下内容:
$.ajax({
type: 'post',
data: $('.category-form').serialize(),
url: $('.category-form').attr('action'),
success: function(res) {
console.log("ajax request success");
$("#area-select").html(res);
$("#category-popup").modal('hide');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("ajax request failed: " + errorThrown);
}
});