Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery上发送$.post后启用链接_Jquery_Click - Fatal编程技术网

在jquery上发送$.post后启用链接

在jquery上发送$.post后启用链接,jquery,click,Jquery,Click,我正在尝试在启用单击之前发送一些ajax帖子 我试过这个: $('.unread a').click(function(){ ele = $(this); $.post('ajax/notification.php', { info : ele.attr('title') }, function(data) { if(data != 'frack') { ele.addClass("read");

我正在尝试在启用单击之前发送一些ajax帖子

我试过这个:

$('.unread a').click(function(){
    ele = $(this);
    $.post('ajax/notification.php', {
    info : ele.attr('title')
    }, 
    function(data) {
        if(data != 'frack') {
            ele.addClass("read");
            ele.removeClass("unread");
            window.location = ele.attr("href");
        }
    });
    return false;
});
但是当我点击链接时,它会直接进入页面,而没有时间发送$.post


有什么想法吗?

这会阻止链接将您发送到某个地方

$('.unread a').click(function(e){
       e.preventDefault();

这会阻止链接执行其默认操作

    preventDefault();
所以


刚刚意识到你已经在做
return false它应该执行与调用
preventDefault()
相同的操作。您可以发布此代码所针对的HTML吗?您的选择器可能是错误的,因此事件处理程序实际上没有被绑定。请确保。您在此页面上没有任何其他JS错误吗?ele.attr(“href”)上有一个错误,该错误应该是ele.parents(“li”).attr(“href”)。我认为它现在起作用了:|我犯了同样的错误,但是
返回false应执行与
preventDefault()相同的操作。
$('.unread a').click(function(e){
    e.preventDefault();
    ele = $(this);
    $.post('ajax/notification.php',
                 { info : ele.attr('title')
                    }, 
        function(data) {
        if(data != 'frack'){
                ele.addClass("read");
                ele.removeClass("unread");
                window.location = ele.attr("href");
            }
        });
    return false;
});