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

194
Vistas
Using variable in another function Javascript

Hello I have a problem with AJAX I got my data from the url but I want to use the variable IsochroneData into the function geo_json_add. How can I do this? I can console log the data that works fine. But getting the variable to the other function is my problem.

$.getJSON("/isochrone", function (data) {
 var isochroneData = data
 console.log(data);
 function geo_json_add(isochroneData) {
   geo_json
   .addData(isochroneData)
   .addTo(map);
 }
 geo_json_add(isochroneData);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

When you want to make a variable global, you've to declare it outside the function then set its value in the function, without the declaratory keyword then it'd be global.

var isochrone; - Outside the function
isochrone = data - In the function

about 4 years ago · Juan Pablo Isaza Denunciar

0

Fix your syntax and indentation

$.getJSON("/isochrone", function (data) {
 var isochroneData = data
 console.log(data);
 function geo_json_add(isochroneData) {
   geo_json
   .addData(isochroneData)
   .addTo(map);
 }
 geo_json_add(isochroneData);
})

if you want to use geo_json_add elsewhere, declare it ouside of the getJSON.

function geo_json_add(isochroneData) {
  geo_json
  .addData(isochroneData)
  .addTo(map);
}

$.getJSON("/isochrone", function (data) {
  var isochroneData = data
  console.log(data);

  geo_json_add(isochroneData);
})
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