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

113
Vistas
Ajax request stop all the website during the working time

I have an issue about a big ajax request: I make a query on a php files which make some curl request, it takes 15-20 seconds to complete, then return some json on my webpage. It's a classic ajax request, but I discovered a strange bug,

When the ajax query is running (type GET), I can't use my website in Chrome, all the pages stay blank until the ajax request is completed,

So I thought the ajax request broken my server, but the site perfectly works on other devices (mobile, other chrome session, ...). It's only the current chrome session which become laggy and work only when the ajax request is completed.

Could you please explain me why? My ajax request is basic:

                    $.ajax({
        url: '/controller.php',
        type: 'GET',
        dataType: "json",
        data: {
            action: "loadPageContent"
        },
        success: function(retour) {
            localStorage.removeItem('myhtml');
            if(retour.status && retour.htmlDatas){
                storedDatas["posts"] = retour.htmlDatas;                        
                storedDatas["date_scrapping"] = retour.date_scrapping;                      
                localStorage.setItem("myhtml", JSON.stringify(storedDatas) ); // ¨Pour si relance

                $('#container').html(retour.htmlDatas);
                

            }
            else {
                alert('error');
            }

        },
        error: function(retour) {
            alert('error');
        },  
    });
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

use promise and handle the response:

async function runCodes(){

    //this code its gonna run async
    ajaxCall().then((response)=>{
       if(response){
          //true
       } else {
          //false
       }
    });

    //some other codes

}
    
    function ajaxCall(){
      return new Promise((resolve) => {
        $.ajax({
            url: '/controller.php',
            type: 'GET',
            dataType: "json",
            data: {
                action: "loadPageContent"
            },
            success: function(retour) {
                localStorage.removeItem('myhtml');
                if(retour.status && retour.htmlDatas){
                    storedDatas["posts"] = retour.htmlDatas;                        
                    storedDatas["date_scrapping"] = retour.date_scrapping;                      
                    localStorage.setItem("myhtml", JSON.stringify(storedDatas) ); // ¨Pour si relance
    
                    $('#container').html(retour.htmlDatas);
                    resolve(true);
    
                }
                else {
                    alert('error');
                    resolve(false);
                }
    
            },
            error: function(retour) {
                alert('error');
                resolve(false);
            },  
        });
      });
    }
over 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