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

86
Visualizações
react undefined response from function ajax request

Hello why its response "callback is not defined"

component 1:

console.log(getUserGps());

component 2:

import $ from 'jquery'
export const getUserGps = () => {
    $.ajax({
        url: "https://geolocation-db.com/jsonp",
        jsonpCallback: "callback",
        dataType: "jsonp",
        success: function(location:any) {
            let city = location.city
            console.log('Pobrano z gps ' + location.city)
            return city
        }
      })
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

jsonpCallback: "callback",

You explicitly told jQuery to tell the server to generate a JSONP program that calls a function named callback.

You didn't define that function.


Remove that line. Let jQuery generate the function from the success property with an automatic name instead.

about 4 years ago · Juan Pablo Isaza Relatório

0

The Problem you have here is, that your aync function has no return-value. What you could do is the following:

const getUserGps = () => {
  return $.ajax({
    url: "https://geolocation-db.com/jsonp",
    jsonpCallback: "callback",
    dataType: "jsonp",
  }).then((location) => {
    return location.city
  })
}

Here you return the request as a promise then you can do the following in your second component:

getUserGps().then(data => {
   console.log(data);
})

Here you have some more information in how async functions and promises work: https://www.w3schools.com/Js/js_promise.asp

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