(Scroll Bar + Ajax)Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eyeinstyin
    New Member
    • Sep 2007
    • 20

    (Scroll Bar + Ajax)Problem

    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),aj ax call should go.My function uses object function call.So how can i use setTimeOut()

    My function looks likes this

    temp contain xmlHTpp object
    Code:
    var temp=new xmlHttpObject();
    
    div.onscroll={temp.makeAjaxCall()};
    here temp.makeAjaxCa ll should not be called until scrolling is stopped alteast for 1000 millisecond
  • Dasty
    Recognized Expert New Member
    • Nov 2007
    • 101

    #2
    I would like to know answer too. But I would make it that way:

    [HTML]<script language="javas cript">
    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){cle arTimeout(timeo utID)}; timeoutID=setTi meout(ajax_func tion,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.

    Comment

    • Eyeinstyin
      New Member
      • Sep 2007
      • 20

      #3
      :( i want object passed to setTimeOut

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        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.

        Comment

        • Eyeinstyin
          New Member
          • Sep 2007
          • 20

          #5
          Originally posted by acoder
          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(obj ect.function(), 100);
          but setInterval takes only string to be passed as function call
          Any Help

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            No, that's not the case. See, for example, this link.

            Comment

            Working...