我尝试将 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 http://www.webtoolkit.info/javascript-utf8.html 进行编码
它对我不起作用
最佳答案
这是一篇关于 JavaScript 中 URL 编码/解码主题的精彩文章:http://roneiv.wordpress.com/2007/12/25/how-to-do-proper-url-encoding-in-javascript-when-using-windowopen/
它使用encodeURI + escape的组合
encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
关于javascript - xmlhttprequest 中的 url 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9803072/