Jquery Ajax Polling jumps to top on every call -
i using below function display active gamelist. problem if player going through list , if there executes ajax call jumps top of div replace response ajax call.
how can avoid jumping of top of div? or other solution should implemented display list of latest games without jumping of on ajax call?
(function pollserverforgamelist() { $.ajax({ url:"<?php echo yii::app()->createurl('game/getgamelist') ?>", data:{'id':<?php echo yii::app()->request->getparam('id')?>}, type:"post", datatype:"html", success:function(response){ $('.multiplayer').html(response); }, }); settimeout(pollserverforgamelist, 2000); }());
single row response data , button join game.
<ul> <li class="first">math</li> <li>rookie</li> <li>guest11</li><li>1</li> <li class="last"><b><a id="join" class="greenbtn" href="/game/multiple?id=4&gameid=20&diff=2&cat=4">join game</a></b> </li> </ul>
multiple row response have multiple <
you try saving current scroll position , returning after insert.
(function pollserverforgamelist() { //save current scroll position var currposition = $(window).scrolltop(); $.ajax({ url:"<?php echo yii::app()->createurl('game/getgamelist') ?>", data:{'id':<?php echo yii::app()->request->getparam('id')?>}, type:"post", datatype:"html", success:function(response){ $('.multiplayer').html(response); //return scroll position $(window).scrolltop(currposition); }, }); settimeout(pollserverforgamelist, 2000); }());
Comments
Post a Comment