如何避免页面刷新锚点(< a>< / a>)标记点击? [英] How to avoid page refreshing on anchor (<a></a>) tag click?

查看:121
本文介绍了如何避免页面刷新锚点(< a>< / a>)标记点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个动态网站。我的问题是当我点击下面的标签:

I'm creating a dynamic website. My problem is when i click on the following tag:

<a class="s-inte" href="set_interesantes.php?n=Frank Melo&u=f6e79cfe9c0ecc4c08dac4c860c4802b&back=http://localhost:8085/Something/success/profile.php?search_user=f6e79cfe9c0ecc4c08dac4c860c4802b&p=12&sa=f6e79cfe9c0ecc4c08dac4c860c4802b&i=2345123&dl=&iv=1">Interesante</a>

页面被刷新,如何避免页面刷新?

The page gets refreshed, How do I avoid this page refresh?

推荐答案

您想要完成的是更新一些无刷新页面的计数器?
您应该使用AJAX技术来做到这一点,这就是AJAX的发明。

What you want to accomplish is to update some counter of interestings w/o refreshing the page? You should do it using AJAX techniques, this is what AJAX was invented for.

请考虑以下代码,它非常简单(需要jQuery库):

Consider the following code, it's top easy (jQuery library required):

<a href="#" class="counter">Interesante</a>

<script>
$(function(){
    $("a.counter").click(function()
    {
         $.get("set_interesantes.php?n=Frank Melo&u=f6e79cfe9c0ecc4c08dac4c860c4802b&back=http://localhost:8085/Something/success/profile.php?search_user=f6e79cfe9c0ecc4c08dac4c860c4802b&p=12&sa=f6e79cfe9c0ecc4c08dac4c860c4802b&i=2345123&dl=&iv=1" );
         .... // you can do some animation here, like a "Liked!" popup or something
         return false; // prevent default browser refresh on "#" link
    });
});
</script>

这篇关于如何避免页面刷新锚点(&lt; a&gt;&lt; / a&gt;)标记点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆