Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Ajax success return value outside function and use it anywhere in the code

I have an Ajax success request and I would like to take the results of the Ajax success function and use it wherever I want in the code. How can I achieve this?

code

    $.ajax({
        url: ajaxurl,
        data: {
            action: "showDbValues",
        },
        success: function(response) {
            let getLastTime = response.data.task_time;
            let getLastTitle = response.data.task_title;
    
            return getLastTime;
    
        },
        error: function(errorThrown) {
            window.alert(errorThrown);
        },
    });
    
    let lastTime = (document.querySelector(".c-add-task-show-time").innerHTML = `${getLastTime}`);
    console.log(lastTime);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could create a variable before the ajax function called foobar. Then set the return value of the Ajax call equal to foobar. As foobar was created outside the scope of the ajax function you should be able to reuse via the foobar variable.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda