By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,716 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,716 IT Pros & Developers. It's quick & easy.

(Scroll Bar + Ajax)Problem

P: 20
Basic Problem is Every scroll of scrollbar makes an ajax call.So if user play with scrollbar say 100 times 100 ajax calls go and server starts processing 100 calls.So abort won't help.The last time the scroll bar has stopped scrolling(say for 1000 millisecond),ajax call should go.My function uses object function call.So how can i use setTimeOut()

My function looks likes this

temp contain xmlHTpp object
Expand|Select|Wrap|Line Numbers
  1. var temp=new xmlHttpObject();
  2.  
  3. div.onscroll={temp.makeAjaxCall()};
  4.  
here temp.makeAjaxCall should not be called until scrolling is stopped alteast for 1000 millisecond
Nov 14 '07 #1
Share this Question
Share on Google+
5 Replies


Dasty
Expert 100+
P: 101
I would like to know answer too. But I would make it that way:

[HTML]<script language="javascript">
var timeoutID = null;

function ajax_function()
{
timeoutID=null;
alert('i am in ajax function');
}
</script>
[/HTML]

and set onscrollevent this way:

[HTML]<div onscroll="if (timeoutID){clearTimeout(timeoutID)}; timeoutID=setTimeout(ajax_function,1000);">[/HTML]

But I am not sure how "hard" it is for browser to start/terminate timeouts (because browser will process onscrollevent many times). Test it and let me know .. If someone else know "cleaner" solution, I would like to hear it too.
Nov 14 '07 #2

P: 20
:( i want object passed to setTimeOut
Nov 22 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Here is something I've not tested, but worth a try:

Use the Date object. Whenever a scroll action takes place, update a variable with the time in milliseconds.

At the same time, a setInterval is continuously running a function every 500 milliseconds. It checks this variable to see if 1000 milliseconds have passed. If not, nothing happens. If they have passed, make the Ajax request.
Nov 22 '07 #4

P: 20
Here is something I've not tested, but worth a try:

Use the Date object. Whenever a scroll action takes place, update a variable with the time in milliseconds.

At the same time, a setInterval is continuously running a function every 500 milliseconds. It checks this variable to see if 1000 milliseconds have passed. If not, nothing happens. If they have passed, make the Ajax request.
Thnx acoder

BUT
The problem is that the function that is to be called from setInterval is object funtion call :(. That is it go be like this

setInterval(object.function(),100);
but setInterval takes only string to be passed as function call
Any Help
Nov 27 '07 #5

acoder
Expert Mod 15k+
P: 16,027
No, that's not the case. See, for example, this link.
Nov 27 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.