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

145
Views
AJAX Data No Showing in a Leaflet Popup Easy Button

I am trying to add JSON response details from an AJAX call to a leaflet popup. I can populate the data using a modal in the html but I want to use this as an easy button function instead.

I have tried a few options but nothing is working to populate the data in the popup and it shows as blank. Everything else is working as it should and the button is added onto the map.

Any ideas?

$('#selCountry').on('change', function(){
  $.ajax({
      url: "php/restCountries.php",
      type: 'POST',
      dataType: 'json',
      data: {
          country: $('#selCountry').val()   
      },
      success: function(result) {
        
          console.log('restCountries', result);
          if (result.status.name == "ok") {
              iso2CountryCode = result.data.alpha2Code;
              var countryName2 = result.data.name;
              countryName = countryName2.replace(/\s+/g, '_');
              
              L.easyButton('<img src="images/info.png">', function(btn, map){
    
              var detailsPopup = L.popup($('#countryName').html('<strong> Country: ' + result['data']['nativeName'] + '</strong>') +
              $('#txtCurrencyCode').html('<strong> Capital City: ' + result['data']['capital'] + '<br> Currency Symbol: '+ result.currency.symbol + '<br> Currency Name: '  + result.currency.name + '<br> Currency Code: ' + result.currency.code + '</strong>')).setContent(popup);
                  detailsPopup.setLatLng(map.getCenter()).openOn(map);
              }).addTo(map);
              
              console.log(result.data.latlng[0]);
              
              var currentLat = result.data.latlng[0]
              var currentLng = result.data.latlng[1]
              
              marker = L.marker;
              
               L.marker([currentLat, currentLng], {icon: redMarker}).addTo(map);
              
                      if (marker != undefined) {
              map.removeLayer(marker);
        };
about 4 years ago · Juan Pablo Isaza
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!