国外一个专门查询IP归属地的数据库geoip,类似国内的纯真数据库,我用ajax查询以后,将查询到的国家的名字返回到本地:
geoip=xmlhttp.responseText;
document.write (geoip);显示在屏幕上的值是:China然后我又判断下:
geoip=xmlhttp.responseText;
document.write (geoip);
if(geoip=="China")
document.write (geoip);这种情况下就还是只显示一个China,也就是说判断后面的那句显示没有执行,即geoip=="China"这个条件不满足,这是为什么呢?直接显示出geoip明明就是China啊?
geoip=xmlhttp.responseText;
document.write (geoip);显示在屏幕上的值是:China然后我又判断下:
geoip=xmlhttp.responseText;
document.write (geoip);
if(geoip=="China")
document.write (geoip);这种情况下就还是只显示一个China,也就是说判断后面的那句显示没有执行,即geoip=="China"这个条件不满足,这是为什么呢?直接显示出geoip明明就是China啊?
可能是被什么标签包着了 ,说不定 。
发现显示的内容有很多,把ajax去查询的那个PHP页的源代码都带回来了……这是怎么回事?
<?php
header("content-type:text/html;charset=utf-8");
header("cache-control:no-cache,must-revalidate");
header("pragma:no-cache");
include("geoip.inc");
$gi=geoip_open("geoip.dat",GEOIP_STANDARD);
$ip=$_SERVER["REMOTE_ADDR"];
$geoip=geoip_country_name_by_addr($gi,$ip);echo $geoip;
geoip_close($gi);
?>但是alert把以上内容全部显示出来了……我不是很懂PHP是不是我的写法没对啊?
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<script type="text/javascript">
function Geoip()
{
var xmlhttp,geoip;
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
xmlhttp=null;
}
}
if(!xmlhttp&&typeof XMLHttpRequest!="undefined")
xmlhttp=new XMLHttpRequest();
xmlhttp.open("get","geoip.php",false);
xmlhttp.send(null);
geoip=xmlhttp.responseText;
if(geoip=="France")
{
window.location.href="http://www.digi-exchange.eu/index_fr.html";
return false;
}
if(geoip=="Germany")
{
window.location.href="http://www.digi-exchange.eu/index_de.html";
return false;
}
if(geoip=="Russian Federation")
{
window.location.href="http://www.digi-exchange.eu/index_ru.html";
return false;
}
if(geoip=="Spain")
{
window.location.href="http://www.digi-exchange.eu/index_es.html";
return false;
}
if(geoip=="Italy")
{
window.location.href="http://www.digi-exchange.eu/index_it.html";
return false;
}
document.write (geoip);
alert(geoip);
if(geoip=="China")
document.write (geoip);
}
</script>
<body onload="javascript:Geoip()"></body>
</html>
这个是html也的完整代码,PHP页代码就是4L的那一块
<html><head></head>
<?php
?>
<body></body>
</html>
这种情况下会把<html><head>这一类的标签显示出来,然后4L的时候我已经把标签都删除了只保留了PHP页的代码,但是还是全部返回了代码,因为我疏忽了一个问题,出了问题后,为了方便测试,我把HTML页通过AJAX访问的PHP页地址设置在了本地,而本地没有PHP支持环境,所以直接把PHP代码也返回了,把去掉了HTML标签以后的PHP页放到网上再测试就正常了我的疏忽,给大家添麻烦了……