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

85
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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