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

133
Visualizações
Ajax response looks undefined

I'm trying to get the ajax response and attribute it to a variable (let's say _has_weekend_hollidays) as follows:


JS Call:

_has_weekend_hollidays = checkWeekendHollidays( _i );
console.log ( checkWeekendHollidays( _i ) );

AJAX Call

$.ajax({
    url: "./directory/ajax_check_weekend_hollidays.php",
    type: "POST",
    data: { 
            start_date: _date1,
            final_date: _date2 
          }
}).done(function (_result) {
    return ( _first_weekday == 0 || _last_weekday_id >= 6 || _result!="0" );
}).fail(function (_result) {
    console.log("ERROR:" + _resultado);
});

The AJAX _result is OK but the return is not working.

So console.log shows undefined.

Any ideas?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you need the result to continue, do your work after the Ajax callback.

It's undefined because there are no variable return by Ajax:

{
    url: "./directory/ajax_check_weekend_hollidays.php",
    type: "POST",
    data: { 
            start_date: _date1,
            final_date: _date2 
          }
}

This line:

return ( _first_weekday == 0 || _last_weekday_id >= 6 || _result!="0" );

is not executed until Ajax is "Done".

It you wish to log the return data, use console.log in the return function.

Example:

$.ajax({
    url: "./directory/ajax_check_weekend_hollidays.php",
    type: "POST",
    data: { 
            start_date: _date1,
            final_date: _date2 
          }
}).done(function (_result) {
    console.log(_first_weekday == 0 || _last_weekday_id >= 6 || _result!="0");
    //do something else here too
}).fail(function (_result) {
    console.log("ERROR:" + _resultado);
});
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