javascript - xmlhttprequest 中的 url 编码

标签 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
       } 

 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/

相关文章:

javascript - 在 Plotly 中取消绑定(bind)点击事件

Python 和 UTF-8 : kind of confusing

python - JSON 包含不正确的 UTF-8\u00ce\u00b2 而不是 Unicode\u03b2,如何在 Python 中修复?

Java - 使用 PreparedStatement 在 mysql 数据库中存储 UTF-8 字符(特别是俄语字符)

javascript - 将二进制数据发送到 servlet

asp.net - YSOD 蓝屏死机 JavaScript RegExp - 语法错误

javascript - 检查现有数据时出现数组值验证错误

javascript - 谷歌地图地理编码不返回位置

javascript - html提交表单ajax响应

GWT-RPC与HTTP Call-哪个更好?