这是我的Jquery代码
<script>
$(document).ready(function(){
$("#target").submit(function(e){
e.preventDefault();
$.post('<?php echo base_url();?>index.php/account/check_user_access',function(data){
if(data=='true'){
}
else{
alert("You are not authorized");
$('body').html(data);
}
});
})
})
</script>现在,当post函数的数据返回true时,我想删除preventDefault.How,我可以这样做吗?
发布于 2014-06-02 15:28:23
试一试
$(document).ready(function () {
$("#target").submit(function (e) {
e.preventDefault();
$.post('<?php echo base_url();?>index.php/account/check_user_access', function (data) {
if (data == 'true') {
//trigger a programatic form submission which will not trigger the submit event handler
$("#target")[0].submit();
} else {
alert("You are not authorized");
$('body').html(data);
}
});
})
})发布于 2014-06-02 15:32:49
使用on解除绑定preventDefault,将off与namespace解除绑定
$(document).ready(function(){
$("#target").on('submit.something',function(e){
e.preventDefault();
$.post('<?php echo base_url();?>index.php/account/check_user_access',function(data){
if(data=='true'){
//now unbind the submit
$(this).off('.something');
}
else{
alert("You are not authorized");
$('body').html(data);
}
});
})
})发布于 2014-06-02 15:33:05
尝尝这个。在此方法中,Ajax调用在处理任何逻辑之前等待响应。如果您的请求失败或不成功,将阻止您的鼠标单击捕获。
$(document).ready(function () {
$("#target").submit(function (e) {
$.post('<?php echo base_url();?>index.php/account/check_user_access', function (data) {
if (data === "true"){
$("#target")[0].submit();
} else {
e.preventDefault();
alert("You are not authorized");
$('body').html(data);
};
});
});
});https://stackoverflow.com/questions/23989263
复制相似问题