I use jQuery to get the visitor’s location through their IP address. There's a great service for this called freeGeoIP . All I need to do is "json" or "xml" at the end of their URL, then add the IP address and return the required data.
When I do this manually in my browser, it works: I get a tiny document to download. When I make a request for $ .ajax or $ .getJSON from a browser, it responds with a “200 OK” heading and metadata below. But the actual data is not coming. What's happening?
EDIT: I added javascript / jQuery code:
function openForm(event,ui){ var _this = $(this); //Get details on the user IP var myIP = $('#yourIP').attr('ip');alert(myIP); var url = 'http://freegeoip.appspot.com/json/' + myIP; $.ajax({ url: url, dataType: 'json', contentType: 'text/json', timeout: 10000, complete: function(ip){ alert('Success Ajax!'); //URL returns status,ip,countrycode,countryname,regioncode,regionname,city,zipcode,latitude,longitude $('#yourIP').text(ip.city + ", " + ip.countryname + " at " + ip.latitude + " latitude."); $('#yourIP').attr({'city': ip.city,'country': ip.countryname}); } }); RESPONSE HEADERS Cache-Control no-cache Content-Type text/json Expires Fri, 01 Jan 1990 00:00:00 GMT Content-Encoding gzip Date Fri, 17 Dec 2010 15:26:48 GMT Server Google Frontend Content-Length 156 REQUEST HEADERS Host freegeoip.appspot.com User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729) Accept application/json, text/javascript, */*; q=0.01 Accept-Language nl,en-us;q=0.7,en;q=0.3 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 115 Connection keep-alive Content-Type text/json Referer http://www.freshbase.nl/permaculture/index.php Origin http://www.freshbase.nl
Wytze source share