I wrote a small piece of information on Friday! There is only an IP address in the database, and most visitors are not sure which city the IP address comes from. If there is one more column in the table to save the city and there is no authenticity. It would be great if the IP address can be turned into a city. Of course, you can go down the database. But it feels a bit wasteful for this requirement. Fortunately, there are many websites that provide query. If the result can be turned into mine, the problem is solved.
A js function is required. Whenever a record comes out, ip is replaced with city:
<script type="text/javascript">
function queryAddress(strID){
try{
var qIp=("ip_"+strID);
var qUrl='/?ipstr='+;
var ajax=new (qUrl,{
method:'get',
onSuccess:function(strResponse){
var resContent=;
var strStruct=((",")+1,);
=(" ")[0];
}
});
}catch(e){}
}
</script>
Write a test case:
<span >221.123.123.123</span><script type="text/javascript">queryAddress('2')</script>
<span >221.123.123.123</span><script type="text/javascript">queryAddress('3')</script>
<span >221.123.123.123</span><script type="text/javascript">queryAddress('4')</script>
List the query URLs I've found:
/?action=queryip&ip_url=221.123.123.123
/?ipstr=221.123.123.123
The above two return only text
/smartresult-xml/?type=ip&q=221.123.123.123
This returns XML
After writing, I realized a problem. Ajax does not support cross-domain submissions. This is not a problem: we write a page with a script. Use the msxml load method to load the target URL! Then we can get the data we are interested in! Refer to this post: /t/20030619/12/
The js code changes slightly:
function queryAddress(strID){
try{
var qIp=("ip_"+strID);
var qUrl='?ip='+;
var ajax=new (qUrl,{
method:'get',
onSuccess:function(strResponse){
=;
}
});
}catch(e){}
}
The following is the ASP file source code:
<%
="text/xml"
="GB2312"
Dim strIP,strPattern
strIP=("ip")
strPattern="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
If strIP="" Or IsNumeric(strIP) then
()
ElseIf Not serRegValidate(strPattern,strIP) then
()
End If
Dim strURL:strURL="/smartresult-xml/?type=ip&q="
set parser=("")
=false
=true
"ServerHTTPRequest",true
(strURL)
if <>0 then
()
end if
set currNode=("//product")
Dim strLocal:strLocal=(0).selectSingleNode("location").text
Split(strLocal," ")(0)
%>
A js function is required. Whenever a record comes out, ip is replaced with city:
Copy the codeThe code is as follows:
<script type="text/javascript">
function queryAddress(strID){
try{
var qIp=("ip_"+strID);
var qUrl='/?ipstr='+;
var ajax=new (qUrl,{
method:'get',
onSuccess:function(strResponse){
var resContent=;
var strStruct=((",")+1,);
=(" ")[0];
}
});
}catch(e){}
}
</script>
Write a test case:
<span >221.123.123.123</span><script type="text/javascript">queryAddress('2')</script>
<span >221.123.123.123</span><script type="text/javascript">queryAddress('3')</script>
<span >221.123.123.123</span><script type="text/javascript">queryAddress('4')</script>
List the query URLs I've found:
/?action=queryip&ip_url=221.123.123.123
/?ipstr=221.123.123.123
The above two return only text
/smartresult-xml/?type=ip&q=221.123.123.123
This returns XML
After writing, I realized a problem. Ajax does not support cross-domain submissions. This is not a problem: we write a page with a script. Use the msxml load method to load the target URL! Then we can get the data we are interested in! Refer to this post: /t/20030619/12/
The js code changes slightly:
Copy the codeThe code is as follows:
function queryAddress(strID){
try{
var qIp=("ip_"+strID);
var qUrl='?ip='+;
var ajax=new (qUrl,{
method:'get',
onSuccess:function(strResponse){
=;
}
});
}catch(e){}
}
The following is the ASP file source code:
Copy the codeThe code is as follows:
<%
="text/xml"
="GB2312"
Dim strIP,strPattern
strIP=("ip")
strPattern="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
If strIP="" Or IsNumeric(strIP) then
()
ElseIf Not serRegValidate(strPattern,strIP) then
()
End If
Dim strURL:strURL="/smartresult-xml/?type=ip&q="
set parser=("")
=false
=true
"ServerHTTPRequest",true
(strURL)
if <>0 then
()
end if
set currNode=("//product")
Dim strLocal:strLocal=(0).selectSingleNode("location").text
Split(strLocal," ")(0)
%>