jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – jQuery在url的末尾添加#,即使我返回false;大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个代码,我贴满了返回false;这样它在执行后不会在URL的末尾附加#,但它仍然会这样做.知道我做错了什么,最好如何/哪里返回虚假?

// Called right away after someone clicks on the Vote up link
    $('.Vote_up').mouseup(function() 
    {        
        $("#loading").show();
        var problem_id = $(this).attr("data-problem_id");

        Vote(problem_id,1);

        //Return false to prevent page navigation
        return false;       
    });

    $('.Vote_down').mouseup(function() 
    {
        $("#loading").show();
        problem_id = $(this).attr("data-problem_id");

        Vote ( problem_id,-1 );

        //Return false to prevent page navigation
        return false;
    });       

// Global function
var Vote = function(problem_id,Vote) 
{
    var dataString = 'problem_id=' + problem_id + '&Vote=' + Vote;

    // The person is actually logged in so lets have him Vote
    $.ajax({
        type: "POST",url: "/auth/check_login.PHP",dataType: "json",success: function(data)
        {
            $.ajax({    
                type: "POST",url: "/problems/Vote.PHP",data: dataString,success: function(html)
                      { 
                           $("#loading").hide();
                           if ( html == "not_logged_in" )
                           {
                               queue.login = false;

                               //set the current problem id to the one within the dialog
                               $problemId.val(problem_id);                  

                               // Try to create the popup that asks user to log in.
                               $("#loginpopup").dialog(  {title: 'Please Login To Vote'} );  // title: 'Login Dialog'

                               // prevent the default action,e.g.,following a link
                               return false;
                           }
                           else
                           if ( html == "already_Voted" )
                           {
                               // Display a dialog Box saying that the user already Voted
                               $('<div>You already Voted this way on this problem.</div>').dialog( {title: 'Already Voted'});
                               // show div which says un-important,hide div which says important

                               $("#support").hide();
                               $("#dont_support").show(); 

                               return false;                              
                           }
                           else
                           if (  html == "error_getTing_Vote" )
                           {
                               $('<div />').html('Error getTing exisTing Votes.').dialog();
                           }
                           else
                           {
                               if ( Vote == -1 )
                               {
                                   $("#support").show();
                                   $("#dont_support").hide();                                                              
                               }
                               else
                               {
                                   $("#support").hide();
                                   $("#dont_support").show();                                                              
                               }

                               // Now make a call to AJAX to get the count of Votes
                               $.ajax({    
                                   type: "POST",url: "/problems/get_Vote_count.PHP",success: function(html)   
                                   {
                                       var class_name = ".Votes_"+problem_id;

                                       $(class_Name).text(html);

                                       return false;                                   
                                   }
                                });    

                                return false;                            
                           }                        
                      },error: function(html) 
                      {
                          $("#loading").hide();

                          return false;
                      } // End of error case    
                }); // Closing inner AJAX call.
            },error: function(data)
            {
                $("#loading").hide();
                $("#loginpopup").dialog( {title: 'Please Login To Vote'} );

                return false;
            } // End of error
        }); // End of outer AJAX.

        return false;
};

解决方法

您应该将事件侦听器绑定到click事件而不是mouseup.触发mouseup时,已经发生了认行为,并且无法再取消.

$('.Vote_down').click(function(E) {
    e.preventDefault();
    // Rest of code

Ps.根据您的代码判断,您有单独的页面投票:

> AJAX请求 – 已登录
> AJAX请求 – 投票

如果投票页面不包含某种身份验证,则此模型非常不安全.用户可以通过创建对投票页面的人为请求来轻松绕过登录页面.

您应该合并登录页面和投票页面.

大佬总结

以上是大佬教程为你收集整理的javascript – jQuery在url的末尾添加#,即使我返回false;全部内容,希望文章能够帮你解决javascript – jQuery在url的末尾添加#,即使我返回false;所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。