我有一个很大的问题,我试图建立一个围绕one page template system
的网站,所以听听它是如何工作的.....用户点击链接:<a href="#" id="<? md5('....').'-link-stay' ?>">.....</a>
但问题是我有超过100个php生成的链接在一个页面上附加到一个监听器,由于一些奇怪的原因,每次点击一个链接,并且用户返回主页面它会使请求加倍....
换句话说:用户点击链接....转到页面.....他看到了很多链接....用户点击链接.....转到页面。但如果用户回去ajax调用双打????
恩。 1个帖子,... 2个帖子..... 4个帖子.... 8个帖子..... 16个帖子..... 32个帖子...... 64个帖子.....
我试图用chrome进行调试,它显示每次调用一个帖子到network(HTTP Request)
的帖子有多少,它显示有多少帖子被制作及其加倍
Html标记:
<script>
// main menu
$('header a').addClass('lvl1Links');
// classifeds
$('#9090 a').addClass('lvl1Links');
//states - citys - cats ads
$('#selectable a').addClass('lvl1Links');
// re-install link management
$(function(){
$('.lvl1Links').click(function(event) {
event.preventDefault();
$('pload').html('<img src="source/image/lbl.gif">');
var page = $(this).attr('id');
var huh = $('input:hidden').val();
var data = 'pop='+huh+'&page='+page;
$.post('source/php/bots/authorize.php',data,function(data){
$('#pager_master_div').html(data).slideDown();
$('pload').html('');
});
});
});
// speacial style on certain input boxes
$('input').addClass('input');
$('#op').removeClass('input');
$('#sp').removeClass('input');
$('button').button();
//$("#BUser_Home_Wrapper a .lvl1Links").removeClass("lvl1Links");
</script><div id="9090"><ol id="selectable"><li class="ui-state-default">
<div class="contr"><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alabama:1">Alabama</a></div><div class="citys"><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alabama:1.Birmingham:1">Birmingham</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alabama:1.Montgomery:2">Montgomery</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alabama:1.Mobile:3">Mobile</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alabama:1.Huntsville:4">Huntsville</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alabama:1.Tuscaloosa:5">Tuscaloosa</a><br><li class="ui-state-default">
<div class="contr"><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alaska:2">Alaska</a></div><div class="citys"><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alaska:2.Anchorage:6">Anchorage</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alaska:2.Juneau:7">Juneau</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alaska:2.Fairbanks:8">Fairbanks</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alaska:2.Sitka:9">Sitka</a><br><a href="#" id="d1457b72c3fb323a2671125aef3eab5d.class.Alaska:2.Ketchikan:10">Ketchikan</a><br></ol></div><style>
.contr{
}
.citys{
display:none;
position:absolute;
height:110px;
width:100px;
top:30px;
left:-5%;
right:-5%;
z-index:100;
background:#FFF;
border-radius:5px;
border:5px #0099FF solid;
font-size:10px;
}
.cityz{
display:none;
position:absolute;
height:200;
width:100px;
top:-100px;
left:-5%;
right:-5%;
z-index:100;
background:#FFF;
border-radius:5px;
border:5px #0099FF solid;
font-size:10px;
}
.citys a{
font-size:15px;
}
.cityz a{
font-size:15px;
}
#selectable li a{
font-size:14px;
}
#selectable li city a{
}
#selectable {
list-style-type: none; margin: 0; padding: 0;
}
#selectable li {
margin:5px;
position:relative;
border-radius:10px;
padding: 1px;
float:left;
width: 100px;
height: 25px;
text-align: center;
}
</style>
<script>
$('.ui-state-default').mouseenter(function(e) {
$('.citys', this).slideDown(); // added this
}).mouseleave(function(e) {
$('.citys', this).toggle(); // added this
});
// bttom rows
$('.ui-state-default').mouseenter(function(e) {
$('.cityz', this).slideDown(); // added this
}).mouseleave(function(e) {
$('.cityz', this).toggle(); // added this
});
</script>
<results></results><input type="hidden" id="fortknox" name="fortknox" value="c4ca4238a0b923820dcc509a6f75849b"><results></results><input type="hidden" id="fortknox" name="fortknox" value="c4ca4238a0b923820dcc509a6f75849b">
<script>
$('input').addClass('input');
$('button').button();
// click event for all links
$(function(){
$('.lvl1Links').click(function(event) {
event.preventDefault();
$('pload').html('<img src="source/image/lbl.gif">');
var page = $(this).attr('id');
var huh = $('input:hidden').val();
var data = 'pop='+huh+'&page='+page;
$.post('source/php/bots/authorize.php',data,function(data){
$('#pager_master_div').html(data).slideDown();
$('pload').html('');
});
});
});
</script>
php代码:
<?
case 'class':
require('functions/cats.php');
classie($p);
break;
function classie($p){
connect();
$state = explode(':',$p[2]);
$total = count($state);
$s = md5('?').'.class.';
$sid = $state[1];
$state = $state[0];
echo "<a href=\"#\" id=\"$s$state:$sid\">$state</a>";
echo "<ol id=\"selectable\">";
if(isset($p[3])){
$city = explode(':',$p[3]);
$cid = $city[1];
$city = $city[0];
echo " : <a href=\"#\" id=\"$s$state:$sid.$city:$cid\">$city</a>";
$sqlca = mysql_query("SELECT * FROM `cats` WHERE `cityId`= ".$cid." ");
while($rowsy = mysql_fetch_array($sqlca)){
echo " : <a href=\"#\" id=\"$s$state:$sid.".$city.":".$cid.".".$rowsy['name'].":".$rowsy['id']."\">".$rowsy['name']."</a>";
}
}
?>
答案 0 :(得分:0)
您可以使用解除绑定单击来解决您的问题,以防止双击和导致 多次进入。看看我在JS上的代码修订版:
$(function(){
$('.lvl1Links').bind(''click,function(event) {
event.preventDefault();
$('pload').html('<img src="source/image/lbl.gif">');
var page = $(this).attr('id');
var huh = $('input:hidden').val();
var data = 'pop='+huh+'&page='+page;
$.post('source/php/bots/authorize.php',data,function(data){
$('#pager_master_div').html(data).slideDown();
$('pload').html('');
});
$(this).unbind(event);
});
});