Javascript xmlhttprequest中的url编码

Javascript xmlhttprequest中的url编码,javascript,utf-8,xmlhttprequest,Javascript,Utf 8,Xmlhttprequest,我正在尝试将xmlhttprequest方法的url编码为utf-8 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

我正在尝试将xmlhttprequest方法的url编码为utf-8

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 ; 
我尝试了以下方法对Url进行编码

它对我不起作用

这里有一篇关于JavaScript中URL编码/解码主题的好文章:

它使用encodeURI和escape的组合

encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));

如果要对字符串进行编码,请使用encodeURIComponent('your'+字符串)或escape('your'+字符串)。希望它能帮助你。它对我的情况没有帮助…url(+地址)中的问题是一个特殊的字符词。它通过使用xmlhttprequest对象的ajax请求发送到php代码中…我所寻找的特殊功能可能是用utf-8编码此地址,这样它就不会在处理Chrome和IE时出现任何问题。显然,该地址已收到损坏且未正确编码…已解决:)