0

所有,我有以下 jQuery 代码:

jQuery(".select_it").click(function(e){
    e.preventDefault();
    song_id = jQuery(this).attr('href');
    music_choice = jQuery("#song_type").val();
    jQuery.post(site_url + "save_song_choice.php", { song_id: song_id, music_choice: music_choice },
        function(response) {
            alert(response);
            var url = site_url + "okyne-form";
            window.location.replace(url);
        });
        return false;
    }
);

当我单击链接时,它不执行 jQuery,而是采取链接被单击的行为。我怎样才能防止这种情况发生?

谢谢!

4

1 回答 1

2

尝试return false;摆脱jQuery.post这样的:

jQuery(".select_it").click(function(e){
    jQuery.post(url, function(){
        //code here   
    });
    return false;
});
于 2012-07-03T03:49:07.590 回答