目前正在开发Codeigniter应用
我使用ajax在bootstrap模式中加载一个视图,加载的视图有一些jquery事件,这些事件还有ajax调用。我得到的问题是,当我点击按钮(将执行ajax)时,它只触发一次,但是在关闭模态并重新打开它之前点击的事件现在运行两次。
$(document).on('click','.open_form',function(e){
e.preventDefault();
var task = $(this).attr('id');
$.ajax({
type: "POST",
url: "<?php echo site_url();?>client/getModalView",
data: {view:'invoice','<?php echo $this->security->get_csrf_token_name(); ? >':'<?php echo $this->security->get_csrf_hash(); ?>','task':task},
cache: false,
context: document.body,
beforeSend:function(){
if(task == 'expense')
{
$('.modal-title').html('Add Expense');
}else if(task == 'uploadexpense'){
$('.modal-title').html('Upload Expense');
}else if(task == 'newDividend'){
$('.modal-title').html('Add new Dividend Voucher');
}else if(task == 'banks'){
$('.modal-title').html('Upload bank Statement');
}else{
$('.modal-title').html('Add Invoice');
}
$('.modal-body').html('<img src="<?php echo site_url();?>assets/images/loading.gif"/>');
},
error:function(msg){
},
success:function(msg){
msg = JSON.parse(msg);
var html = '';
$('#script').html(msg['script']);
if(msg['file'] != '')
{
html = msg['file'];
}
html += msg['html'];
$('.modal-body').html(html);
}
});
return false;
});