var xmlHttp;
function getIPByPHP(ip)
{
if (ip.length==0){
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser does not support HTTP Request");
return;
}
var url="ip.php";
url=url+"?ip="+ip;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
//document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
var json = ""+xmlHttp.responseText;
var obj = eval("(" + json + ")");
lat = obj.latitude;//纬度
longitude = obj.longitude;//经度
countryCode = obj.country_code;
country = obj.country_name;
city = obj.city;
ip = obj.ip;
ipLatLng = new google.maps.LatLng(lat,longitude);
chunZhenCountry = obj.chunzhen_country;
chunZhenArea = obj.chunzhen_area;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
用jquery吧
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function(){
$("#ajaxad").html("载入中").load("ajax.php");
});
</script>
<div id="ajaxad"></div>