Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
JS-JQuery window.scroll triggering multiple requests in Mozilla Firefox

I have implemented lazy load of content on my webpage in the following way:

Initial Load: func1: Get information of 10 brands via ajax call(Also returns total expected data). func2: Get products information of the 10 brands recieved in above function via ajax.

if ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.7){
       if(totaldatarecvd < totalExpectedData){
         func1: Get information for next 10 brands via ajax call.
        func2: Get products information of the 10 brands recieved in above function via ajax.
       }

      }

Issue: On Google chrome it works Fine, while on Mozilla Firefox when user has scrolled the screen 70% multiple ajax requests are being made and thus the order of data rendered gets disrupted. Expected: When 70% screen scrolled, make one ajax request to fetch next 10 data. On further scroll fetch next 10 brands and so on.

Please suggest how can lazy load be implemented with one request at a time.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I believe you are experiencing this behavior because when you scroll a page using, for example, the wheel of a mouse, what you are actually doing is scrolling the page for X pixels at a time (say, 20 pixels with one wheel "scroll"). The scroll event, however, is triggered every time the page is scrolled down 1 pixel. Therefore, any functionality you have assigned to the scroll event should theoretically be executed 20 times per each wheel "scroll".

Solution: Add a (global) variable that will control whether the desired scroll position has been reached (and therefore a data load has been initiated), and use that to prevent multiple data load requests. The variable should initially be set to false, and once the desired scroll position has been reached, set to true and initiate the data load.

Don't forget to set it to false after the data load has been completed, else it will only work for the first time.

dataLoading = false;

if ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.7 && !dataLoading){

    dataLoading = true;

    if(totaldatarecvd < totalExpectedData){
        func1: Get information for next 10 brands via ajax call.
        func2: Get products information of the 10 brands recieved in above function via ajax.
    }

}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!