2015-06-16 28 views
0
<a id="link" href="http://google.com">Let's Go</a> 

$("#link").on("click", function(){ 

    $.post("process.php", 
        { 
         x: pos.x, 
         y: pos.y 
        }, 
        function(data, status){ 
         // do something here 
       }); 
      }); 

    }); 

当点击Let's Go链接时会发生什么?浏览器是否等待发送请求并从process.php页获取结果?或忘记请求并立即关注链接?当我在链接上发送ajax请求时会发生什么?

回答

0

href会覆盖任何JS函数。所以在你的情况下,它只会重定向到http://google.com。如果你想让它忽略href,那么你需要使用这样的e.preventDefault()

$("#link").on("click", function(e){ 
    e.preventDefault(); 
    //... more code 
}); 
相关问题