Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!