ajax在ie与firfox的乱码解决

今天做网站时,使用ajax,传入action的编码,在ie中传入的和在firfox中传入的总是不一样,郁闷了一把。我的jsp文件保存格式是utf8,接收与响影也是设置的utf8,在ie中传入的是“gb2312”,在firfox中传入的是utf8。
结果是不知道怎么设置了。最后解决方案是:
<script type="text/javascript">
    var xmlHttpRequest;
	function display(name){
        var url = "mapline?name="+encodeURIComponent(name);//主要在这里对汉字进行一下转换
        sendRequest(url);
	}
	function hide(name){
		if(last!=""){
			document.getElementById(name).style.display="none";
		}
	}
	function msg(text){
		document.getElementById("kehu").innerHTML=text;
	}
    //ajax取线路数据
    function createXMLHttpRequest(){
        if(window.ActiveXObject){
              try{
                xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
              }catch(e){
                  xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
              }
        }else{
            xmlHttpRequest = new XMLHttpRequest();
        }
    }

    function sendRequest(url){
        createXMLHttpRequest();
        xmlHttpRequest.open("get", url);
        xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        xmlHttpRequest.onreadystatechange=process;
        xmlHttpRequest.send(null);
        
    }
    function process(){
        if(xmlHttpRequest.readyState==4){
            if(xmlHttpRequest.status==200){
                update();
            }
        }
    }
    function update(){
        document.getElementById("kehu").innerHTML="";
        var xmlmess = xmlHttpRequest.responseXML;
        var lines = xmlmess.getElementsByTagName('line');
        if(lines.length==0){
            document.getElementById("kehu").innerHTML="<center><font style='color:red;font-weight:900' size='2' >暂无旅游线路</font></center>";
        }else{
            for(var i = 0;i<lines.length;i++){
                var id = lines[i].getAttribute("id");
                var name = lines[i].getAttribute("name");
                var img = document.createElement("img");
                img.setAttribute("src", "images/tel.gif");
                var a = document.createElement("a");
                a.setAttribute("href", "detailed?id="+id);
                var tname = document.createTextNode(name);
                a.appendChild(tname);
                var br = document.createElement("br");
                document.getElementById("kehu").appendChild(img);
                document.getElementById("kehu").appendChild(a);
                document.getElementById("kehu").appendChild(br);
            }
        }

         for(i=1; i <8; i++) {  //将国内游全部设为none
                    document.getElementById("mod"+i).className="menuNo";
                    document.getElementById("slidingList"+i).className="slidingList_none";
         }
        document.getElementById("kehu").className="slidingList";//只显示地图的这一个div
           
    }
</script>

服务器接收入下
String name =new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8");

你可能感兴趣的:(JavaScript,Ajax,IE,Microsoft,旅游)