得到xmlHttpRequest對象
function getXMLHttpRequest(){
if (window.XMLHttpRequest){//Firefox、Opera等經過window.XMLHttpRequest來建立xmlhttp對象。
return new XMLHttpRequest();
}else if(window.ActiveXObject){//IE中使用ActiveXObject方式建立XmlHttp對象
for(var i =5;i>1;i--){
try{
if(i==2){
return new ActiveXObject( "Microsoft.XMLHTTP" );
}else{
return new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );//
}
}catch(ex){}
}
}
}
var reqcity;
var cflag=true;
function chkCityIP(){//
var host = window.location.host;
//進入條件
if(host.indexOf("localhost")>-1){
reqcity = getXMLHttpRequest();
reqcity.open("POST", "/uwp/newServlet?serviceName=WebServiceMag&medthodName=chkCityIP", true); //接受參數的方法 或(servlet)
reqcity.onreadystatechange = returnchkCityIP;
reqcity.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
reqcity.send(null);//這裏是傳參數 個人方法不須要額外參數 因此是null 須要額外參數 可用下面註解的
//reqcity.send("productID="+productID+"&MemberID="+MemberID+"&curDesignerID="+curDesignerID+"&booktopdf="+booktopdf);
}
} app
function returnchkCityIP(){
if (reqcity.readyState==4&&reqcity.status==200){
var txt = reqcity.responseText;//返回的字符串數據
var yu = txt.split("&")[1];
var cs = txt.split("&")[0];
if(){
}else if(){
}else{
}
}
}
window.onload=chkCityIP(); url