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

315
Visualizações
Take a variable from a HTTPGET request and create a if statement function?

Sorry if this is incorrectly posted, I am new to all of this.

I have a weather API that provides weather conditions in the variable called conditions. I would like to take that variable and make a if statement function with it as a parameter. I will be then setting the variable weather_genre for the second API to this function ("Horror" is a place holder).

// location get api $.getJSON("https://ipgeolocation.abstractapi.com/v1/?api_key=41b35af8793c40819cf4cf013b54802c", function(data) { console.log(data); var longlat = data["longitude"]+","+ data["latitude"];

         // weather get api (long,lat)
        $.getJSON("https://devapi.qweather.com/v7/weather/now?unit=i&lang=en&key=86a7ff0e360e463db560e321bd071d25",{"location" : longlat}, function(data){
        console.log(data);
        var conditions = data["now"]["text"];
        //$('#weather').html(conditions);
        });
    })


    //anime post api
    var weather_genre = "Horror";
   // Here we define our query as a multi-line string
    // Storing it in a separate .graphql/.gql file is also possible
    var query = `
        query ($genre: String) { # Define which variables will be used in the query (id)
        Media (type: ANIME, genre: $genre) { # Insert our variables into the query arguments (id) (type: ANIME is hard-coded in the query)
            id
            title {
            english
            }
        }
        }
        `;
            // Define our query variables and values that will be used in the query request
            var variables = {
                genre: weather_genre
           };
            // Define the config we'll need for our Api request
            var url = 'https://graphql.anilist.co',
                options = {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                    },
                    body: JSON.stringify({
                        query: query,
                        variables: variables
                    })
                };
            // Make the HTTP Api request
            fetch(url, options).then(handleResponse)
                .then(handleData)
                .catch(handleError);
            function handleResponse(response) {
                return response.json().then(function (json) {
                    return response.ok ? json : Promise.reject(json);
                });
            }
            function handleData(data) {
                console.log(data);
            }
            function handleError(error) {
                alert('Error, check console');
                console.error(error);
            }
about 4 years ago · Juan Pablo Isaza
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