TypeError: $(…).modal is not a function in yii1
TypeError: $(…).modal is not a function in yii1
我有一个按钮,当我点击它时会出现一个模式弹出窗口。然后我输入数据并使用 ajax 提交表格。提交数据后,我希望模式关闭。这是我试过的(相关代码)
$form=$this->beginWidget('CActiveForm', array(
'id'=>'employee-task-form',
'enableAjaxValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'afterValidate'=>'js:function(form,data,hasError){
if(!hasError){
$.ajax({
"type":"POST",
"url":"'.CHtml::normalizeUrl(array('employeetasks/create','ajax')).'",
"data":form.serialize(),
"success":function(){
toastr.success("Saved successfully.", "Success");
$("#ajaxModal").modal("close");
// $("#ajaxModal").modal("hide");
},
});
}
}'
),
));
<script type="text/javascript">
jQuery('document').ready(function($){
jQuery("body").on("click", ".popup", function (e)
{
var url = $(this).attr("href");
$("#ajaxModal").find(".modal-body").load(url + "?ajax=1", false, function (responseText, status, req)
{
if (status != "error") {
$("#ajaxModal").modal({backdrop: "static", keyboard: true});
}
else
toastr.error("Failed to load", "Loading failed");
});
e.preventDefault();
});
});
</script>
数据正在保存,即,Ajax 功能正在运行,烤面包机也正在运行,但模态未关闭,我收到类似 Uncaught TypeError: $(...).modal is not a function 的错误。
编辑
我在 Yiiframework 论坛发了同样的问题Link
他们说我无法关闭模态,因为 jQuery 中不存在 modal() 函数,是这样吗?
我能够使用此代码隐藏模式 $("#ajaxModal").hide();
但背景仍然是灰色(与模式弹出时的颜色相同)
编辑
嗨,我试过这样
$("#ajaxModal").hide();
$("body").removeClass("modal-open");
$(".modal-backdrop").remove();
然后我要关闭模态框,但下次当我点击按钮时模态框不会弹出。
找到错误原因了。我在 bootstrap.min.js 之前调用模态。这就是我获得 TypeError: $(…).modal is not a function
的原因
错误。
我有一个按钮,当我点击它时会出现一个模式弹出窗口。然后我输入数据并使用 ajax 提交表格。提交数据后,我希望模式关闭。这是我试过的(相关代码)
$form=$this->beginWidget('CActiveForm', array(
'id'=>'employee-task-form',
'enableAjaxValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'afterValidate'=>'js:function(form,data,hasError){
if(!hasError){
$.ajax({
"type":"POST",
"url":"'.CHtml::normalizeUrl(array('employeetasks/create','ajax')).'",
"data":form.serialize(),
"success":function(){
toastr.success("Saved successfully.", "Success");
$("#ajaxModal").modal("close");
// $("#ajaxModal").modal("hide");
},
});
}
}'
),
));
<script type="text/javascript">
jQuery('document').ready(function($){
jQuery("body").on("click", ".popup", function (e)
{
var url = $(this).attr("href");
$("#ajaxModal").find(".modal-body").load(url + "?ajax=1", false, function (responseText, status, req)
{
if (status != "error") {
$("#ajaxModal").modal({backdrop: "static", keyboard: true});
}
else
toastr.error("Failed to load", "Loading failed");
});
e.preventDefault();
});
});
</script>
数据正在保存,即,Ajax 功能正在运行,烤面包机也正在运行,但模态未关闭,我收到类似 Uncaught TypeError: $(...).modal is not a function 的错误。
编辑
我在 Yiiframework 论坛发了同样的问题Link
他们说我无法关闭模态,因为 jQuery 中不存在 modal() 函数,是这样吗?
我能够使用此代码隐藏模式 $("#ajaxModal").hide();
但背景仍然是灰色(与模式弹出时的颜色相同)
编辑
嗨,我试过这样
$("#ajaxModal").hide();
$("body").removeClass("modal-open");
$(".modal-backdrop").remove();
然后我要关闭模态框,但下次当我点击按钮时模态框不会弹出。
找到错误原因了。我在 bootstrap.min.js 之前调用模态。这就是我获得 TypeError: $(…).modal is not a function
的原因
错误。