2012-03-21 62 views
0

荫试图编码的XMLHttpRequest方法的URL为UTF-8URL编码

var Url=("http://localhost/day1/tryconnect.php?add="+address) ;  // the server script to handle the request 
if (window.XMLHttpRequest) { 
     xmlhttp= new XMLHttpRequest() ;  // For all modern browsers 
     } 

else if (window.ActiveXObject) { 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") ; // For (older) IE 
} 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
{ 
alert("connection is stable") ; 
} 


xmlhttp.open("GET", Url, false); 
xmlhttp.send(null); 
var xml = xmlhttp.responseXML ; 

我尝试以下方法来编码地址http://www.webtoolkit.info/javascript-utf8.html
它并没有为我

+0

如果要编码字符串,请使用encodeURIComponent('your'+ string)或escape('your'+ string)。 希望它可以帮助你。 – 2012-03-21 10:54:38

+0

它没有帮助我的情况...在url http://localhost/day1/tryconnect.php?add =“+地址 (+地址)的问题是一个特殊的字符..并将其发送到php代码通过使用xmlhttprequest对象的ajax请求...特殊的所有我期待的可能是编码这个地址在utf-8,以便它不会使任何问题处理Chrome和IE ..显然地址收到损坏并没有正确编码... – 2012-03-21 11:07:45

+0

解决:) http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript – 2012-03-21 11:29:44

回答