ajax联动地市在ie可以, Safari 、搜狗等手机浏览器却不行 【居然没人看得出问题吗】
本帖最后由 zhangshichuan119 于 2013-03-29 10:27:03 编辑 奇怪的是 xmlHttp.responseTEXT 在Safari 、搜狗等手机浏览器 这里就取不到值。
ie正常。
代码可以直接复制到html文件里面执行。
上码.....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi" />
<SCRIPT src="http://124.232.150.182:8080/wap_mark/back/js/lazyload-min.js" type=text/javascript></SCRIPT>
<script language="javascript"><!--
function intiWidth(){
if((window.screen.width>500||window.screen.width<450)&&window.screen.width>320){
var targetWidth = 480/window.screen.width * window.devicePixelRatio * 160;
targetDensitydpi = 'target-densitydpi=' + targetWidth + ', width=device-width,user-scalable=no';
document.getElementsByName('viewport')[0].setAttribute( 'content', targetDensitydpi );
}
}
function loadscript(){
LazyLoad.js(['http://124.232.150.182:8080/wap_mark/back/js/jquery-1.7.2.min.js'], function () {
intiWidth();
});
}
setTimeout(loadscript,1);
var xmlHttp;
var result;
function createXMLHttpRequest()
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function getcitytown()
{
var provinceID = document.all.selectp.value
createXMLHttpRequest();
var url="http://124.232.150.182:8080/wap_mark/search.jsps?p=selTownByCity&provinceID="+provinceID;
xmlHttp.open("post",url,true);
//xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = callbackCity;
xmlHttp.send(null);
}
function callbackCity()
{
var serviceType = document.getElementById("selectc");
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
result = xmlHttp.responseTEXT;//服务器返回值,假设返回值为1
var arr=trim(result).split(",");
if(!isNaN(arr[0].split(":")[0])){
for(var i=serviceType.options.length;i>=1;i--)
{
serviceType.options.remove(i)
}
for(var i=0;i<arr.length-1;i++)
{
var arr1 = arr[i].split(":");
if(arr1 === undefined)
continue;
var name = 'null';
var newoption = document.createElement("option");
newoption.innerText=arr1[1];
newoption.value=arr1[0];
if(arr1[0] == '1' )
{
newoption.selected="selected";
document.getElementById("selectc").appendChild(newoption);
}
else
{
document.getElementById("selectc").appendChild(newoption);
}
}
}
}
}
}
//去左空格;
function ltrim(s)
{
return s.replace( /^\s*/, "");
}
//去右空格;
function rtrim(s)
{
return s.replace( /\s*$/, "");
}
//左右空格;
function trim(s)
{
return rtrim(ltrim(s));
}
</script>
</head>
<body style="background-color: #f4f4f4" onload="javascript:alert('我的地址');">
<form name="form1" method="post" action="hupdateAdr&OoiqOcgcNSygddumFqqhIQk+sg4SL1KaW6pwaIMZn30=">
<table >
<select class="sel" name="selectp" id="selectp" onchange="getcitytown();" style="background-image:http://124.232.150.182:8080/wap_mark//images/city.png ">
<option value="0"> 省份 </option>
<option value="1"> 辽宁 </option>
<option value="2"> 青海 </option>
<option value="3"> 新疆 </option>
<option value="4"> 陕西 </option>
<option value="5"> 上海 </option>
<option value="6"> 四川 </option>
<option value="7" selected> 山西 </option>
<option value="8"> 山东 </option>
<option value="9"> 天津 </option>
<option value="10"> 西藏 </option>
<option value="11"> 浙江 </option>
<option value="12"> 云南 </option>
<option value="13"> 内蒙古 </option>
<option value="14"> 宁夏 </option>
<option value="15"> 重庆 </option>
<option value="16"> 安徽 </option>
<option value="17"> 北京 </option>
<option value="18"> 甘肃 </option>
<option value="19"> 福建 </option>
<option value="20"> 广西 </option>
<option value="21"> 广东 </option>
<option value="22"> 贵州 </option>
<option value="23"> 河南 </option>
<option value="24"> 河北 </option>
<option value="25"> 黑龙江 </option>
<option value="26"> 海南 </option>
<option value="27"> 湖南 </option>
<option value="28"> 湖北 </option>
<option value="29"> 吉林 </option>
<option value="30"> 江苏 </option>
<option value="31"> 江西 </option>
</select>
<select name="selectc" id="selectc" class="sel">
<option value="0"> 城市 </option>
</select>
</table>
</form>
</body>
</html>
//result = xmlHttp.responseTEXT
result = xmlHttp.responseText