jQueryを使用して、IPアドレスで訪問者の場所を取得しています。これにはfreeGeoIPという素晴らしいサービスがあります。私がする必要があるのは、URLの末尾に「json」または「xml」を付けてIPアドレスを追加するだけで、必要なデータが返されます。jQuery JSONリクエストで「200 OK」という回答が得られますが、内容はありません
ブラウザでこれを手動で実行すると、動作します。小さな文書をダウンロードできます。ブラウザから$ .ajaxまたは$ .getJSONリクエストを行うと、 '200 OK'ヘッダーと下のメタデータで応答します。しかし、実際のデータは入っていません。何が起こっていますか?
編集:私はジャバスクリプト/ jQueryのコードを追加しました:
function openForm(event,ui){
var _this = $(this);
//Get details on the user's 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
$ .ajax()関数が正しく設定されていない可能性があるので、実際にはコードのスニペットを指定する必要があります。 – Soviut
なぜ、リクエストヘッダからremote_addrを取得できないのですか?私はコードを見るための概念の2番目のものです。 – jMyles
もちろん、コードが登場です! – Wytze