Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda