首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

ajax联动地市在ie可以, Safari 、搜狗等手机浏览器却不行 【居然没人看得出有关问题吗】

2013-04-02 
ajax联动地市在ie可以, Safari 、搜狗等手机浏览器却不行 【居然没人看得出问题吗】本帖最后由 zhangshichuan

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">&nbsp;&nbsp;省份&nbsp;&nbsp; </option>
        
         <option value="1">&nbsp;&nbsp;辽宁 &nbsp;&nbsp;</option>
        
         <option value="2">&nbsp;&nbsp;青海 &nbsp;&nbsp;</option>
        
         <option value="3">&nbsp;&nbsp;新疆 &nbsp;&nbsp;</option>
        
         <option value="4">&nbsp;&nbsp;陕西 &nbsp;&nbsp;</option>
        
         <option value="5">&nbsp;&nbsp;上海 &nbsp;&nbsp;</option>
        
         <option value="6">&nbsp;&nbsp;四川 &nbsp;&nbsp;</option>
        
         <option value="7" selected>&nbsp;&nbsp;山西&nbsp;&nbsp;</option>
        
         <option value="8">&nbsp;&nbsp;山东 &nbsp;&nbsp;</option>
        
         <option value="9">&nbsp;&nbsp;天津 &nbsp;&nbsp;</option>
        
         <option value="10">&nbsp;&nbsp;西藏 &nbsp;&nbsp;</option>
        
         <option value="11">&nbsp;&nbsp;浙江 &nbsp;&nbsp;</option>
        


         <option value="12">&nbsp;&nbsp;云南 &nbsp;&nbsp;</option>
        
         <option value="13">&nbsp;&nbsp;内蒙古 &nbsp;&nbsp;</option>
        
         <option value="14">&nbsp;&nbsp;宁夏 &nbsp;&nbsp;</option>
        
         <option value="15">&nbsp;&nbsp;重庆 &nbsp;&nbsp;</option>
        
         <option value="16">&nbsp;&nbsp;安徽 &nbsp;&nbsp;</option>
        
         <option value="17">&nbsp;&nbsp;北京 &nbsp;&nbsp;</option>
        
         <option value="18">&nbsp;&nbsp;甘肃 &nbsp;&nbsp;</option>
        
         <option value="19">&nbsp;&nbsp;福建 &nbsp;&nbsp;</option>
        
         <option value="20">&nbsp;&nbsp;广西 &nbsp;&nbsp;</option>
        
         <option value="21">&nbsp;&nbsp;广东 &nbsp;&nbsp;</option>
        
         <option value="22">&nbsp;&nbsp;贵州 &nbsp;&nbsp;</option>
        
         <option value="23">&nbsp;&nbsp;河南 &nbsp;&nbsp;</option>
        
         <option value="24">&nbsp;&nbsp;河北 &nbsp;&nbsp;</option>
        
         <option value="25">&nbsp;&nbsp;黑龙江 &nbsp;&nbsp;</option>
        
         <option value="26">&nbsp;&nbsp;海南 &nbsp;&nbsp;</option>
        
         <option value="27">&nbsp;&nbsp;湖南 &nbsp;&nbsp;</option>
        
         <option value="28">&nbsp;&nbsp;湖北 &nbsp;&nbsp;</option>
        
         <option value="29">&nbsp;&nbsp;吉林 &nbsp;&nbsp;</option>
        
         <option value="30">&nbsp;&nbsp;江苏 &nbsp;&nbsp;</option>
        
         <option value="31">&nbsp;&nbsp;江西 &nbsp;&nbsp;</option>


        
      </select>
      
    
      <select name="selectc" id="selectc"  class="sel">
        <option value="0">&nbsp;&nbsp;城市 &nbsp;&nbsp;</option>
            </select>
      
</table>
</form>
</body>
</html>
 


[解决办法]
首先,XMLHttpRequest对象是属性区分大小写的,acx创建的不区分,参考:ajax对象常用属性,事件,方法大小写问题

//result = xmlHttp.responseTEXT
result = xmlHttp.responseText



第二,看你这个url地址明显就跨域了,acx本地浏览器可以跨域请求,但是xmlhttprequest不行。

你这个只能使用jsonp来操作,如果跨域的页面不支持jsonp操作,你就只能使用yahoo的jsonp跨域接口来实现了

自己看这些
jQuery jsonp跨域原理
http://query.yahooapis.com/v1/public/yql JSONP跨域接口API使用说明
JSONP跨域访问在线代理API

热点排行