简体   繁体   中英

getJSON inside another getJSON

I'm trying to get the IP address and GPS coordinates of the client. Using jQuery, I have this:

 $.getJSON("http://jsonip.appspot.com/", function(data) { var locationURL = "http://freegeoip.net/json/" + data.ip; $('#IPdiv').html(locationURL); $.getJSON(locationURL, function(locationData) { $('#GPSdiv').html(locationData.country_name); console.log(locationData); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id='IPdiv'></div> <div id='GPSdiv'></div> 

First I'm requesting the users IP address from an external site. Then I use the returned data to create another URL that is called. Sadly, the inner getJSON method isn't being run. Firebug doesn't even show the URL being called. What am I doing wrong?

EDIT:

Problem solved. The Ghostery plugin was blocking freegeoip.net.

Problem solved: The Ghostery plugin was blocking freegeoip.net. What I learned from this experience: Always check if the Ghostery icon shows anything being blocked while working on your site!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM