2016-03-30 23 views
0

Freecodecamp bir görev üzerinde çalışıyorum, Görev yerel hava göstermek ve dolayısıyla kullanıcının yerini almak zorunda. Ben from here konum alabilirim ama baskı sonra ben null yanıt veren JS kullanarak basılmış bir div getElementById için çalışıyordum yazdırdıktan sonra. Anahtar değer çiftini almak istiyorum, böylece onlarla bir şeyler yapabilirim. PeşinGeo Location Trace getElementById çalışmıyor

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 
 
     <title>Location Trace | freecodecamp Challanges</title> 
 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
 
    </head> 
 
    <body> 
 
     <div id="GeoResults"></div> 
 
     <script> 
 
     $.getJSON("http://ip-api.com/json/?callback=?", function(data) { 
 
      var table_body = ""; 
 
      var count = 0; 
 
      $.each(data, function(k, v) { 
 
\t \t \t \t //JSON.stringify(j); // '{"name":"binchen"}' 
 
\t \t \t \t 
 
\t \t \t \t table_body += '<div id=Coun_'+count+'>'+v+'</div>'; 
 
\t \t \t \t 
 
       //table_body += "<tr><td id='FC_"+count+"'>" + k + "</td><td><b id='SC_"+count+"'>" + v + "</b></td></tr>"; 
 
       count++; 
 
      }); 
 
      $("#GeoResults").html(table_body); 
 
     }); 
 
     </script> 
 
     <script> 
 
\t \t \t var x = document.getElementById('Coun_1') /*= 'Dooone!!!'*/; 
 
\t \t \t console.log(x); 
 
     </script> 
 
    </body> 
 
</html>

Teşekkür: İşte benim kodudur!

+3

Çok getElementById bu öğelerin henüz hızlı cevap Arun için dom –

+0

sayesinde eklenmez çağrıldığında, lütfen bana yardım edebilir, bir zaman uyumsuz API kullanarak bu öğeleri ekliyoruz sadece Async hakkında detaylandırılarak burada. Nereden başlarım? Async hakkında –

+0

http://stackoverflow.com/questions/3393751/what-does-asynchronous-means-in-ajax – GuRu

cevap

0

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 
 
     <title>Location Trace | freecodecamp Challanges</title> 
 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
 
    </head> 
 
    <body> 
 
     <div id="GeoResults"></div> 
 
     <script> 
 
     $.getJSON("http://ip-api.com/json/?callback=?", function(data) { 
 
      var table_body = ""; 
 
      var count = 0; 
 
      $.each(data, function(k, v) { 
 
\t \t \t \t //JSON.stringify(j); // '{"name":"binchen"}' 
 
\t \t \t \t 
 
\t \t \t \t table_body += '<div id=Coun_'+count+'>'+v+'</div>'; 
 
\t \t \t \t 
 
       //table_body += "<tr><td id='FC_"+count+"'>" + k + "</td><td><b id='SC_"+count+"'>" + v + "</b></td></tr>"; 
 
       count++; 
 
      }); 
 
      $("#GeoResults").html(table_body); 
 
      var x = document.getElementById('Coun_1').innerHTML; /*= 'Dooone!!!'*/; 
 
\t \t \t console.log(x); 
 
     }); 
 
     </script> 
 
    </body> 
 
</html>