Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop scrolling to top after AJAX request [duplicate]

Tags:

Possible Duplicate:
How do I stop a web page from scrolling to the top when a link is clicked that triggers javascript?

my browser scrolls to top after ajax request then i use

 $('html, body').animate({ scrollTop: $('#loadMore').offset().top }, 2000);

to scroll back to my div. is there a way i stop it from scrolling to top from the beginning

like image 706
Miroo Avatar asked Mar 27 '11 14:03

Miroo


People also ask

How do I cancel my ongoing ajax request?

ajax({ type: 'POST', url: 'someurl', success: function(result){} }); request. abort();

How do I stop a scroll event?

We can't prevent scrolling by using event. preventDefault() in onscroll listener, because it triggers after the scroll has already happened. But we can prevent scrolling by event. preventDefault() on an event that causes the scroll, for instance keydown event for pageUp and pageDown .

How do I send ajax requests every second?

ajax({ type: 'POST', url: 'increment. php', data: $(this). serialize(), dataType: 'json', success: function (data) { $('#hidden'). val(data);// first set the value }, complete: function (data) { // Schedule the next setTimeout(doAjax, interval); } }); } setTimeout(doAjax, interval);


1 Answers

you should add return false to the end of your ajax call function. Or to the end of your inline call:

<a href="#" onclick="someAjaxCall(); return false">Link</a>
like image 137
fl00r Avatar answered Sep 20 '22 01:09

fl00r