【发布时间】:2016-01-06 04:39:47
【问题描述】:
P.S 我的 javascript 不是很好,我知道有人问过这个问题,但解决方案不适用于我的问题,所以我会再次问这个问题。
我被这个问题困住了,还没有找到解决方案。我想清除模态关闭后发生的所有事情。
我的模态是一个表单模态,所以每当我点击提交时,codeigniter 验证消息将通过在 <div style="font-size:10px;width:50%;" id="info"></div> 上使用 ajax 来显示。现在,每当我关闭模式时,验证消息都会在我重新打开时保留。关闭模态后应该怎么做才能清除这些?
这是ajax调用的函数:
public function addcomp () {
$this->load->library('form_validation');
$this->load->helper('security');
$this->form_validation->set_rules('comp_name','Computer Name','trim|required|callback_pc_exist');
$this->form_validation->set_rules('status','Status','trim|required');
$this->form_validation->set_rules('location','Location','trim|required');
if ($this->form_validation->run()) {
$this->load->model('asset_model');
$result=$this->asset_model->addpc();
if (!$result) {
echo mysqli_error($result);
} else {
echo "<div class='alert alert-success alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
Computer Successfully Added!</div>";
}
}
echo validation_errors("<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>","</div>");
}
这是提交调用的ajax:
$(document).ready(function(){
$("#addpc").submit(function(){
var formdata=$("#addpc").serialize();
$.ajax({
url:"asset_management/addcomp",
type:"POST",
data: formdata,
async: true,
}).done(function( formdata ) {
$('#info').html(formdata);
$("#addpc")[0].reset();
viewdata();
});
return false;
});
});
【问题讨论】:
-
如何添加验证消息?有具体的吗?
-
@PraveenKumar 编辑了我的帖子
-
是的,已检查。请检查我的答案。将
#info替换为.alert-error或任何需要删除的类。 -
更新的答案对你有帮助吗,哥们?
标签: javascript jquery twitter-bootstrap bootstrap-modal