【发布时间】:2026-02-08 16:35:01
【问题描述】:
我必须使用 UTF-8 发送此请求,但它不起作用。
如何使用 UTF-8 格式发送此请求?
var request = new ActiveXObject("Microsoft.XMLHTTP");
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
// ret
}
}
httpUrl="/ISV/AddCustomerWebSite/Default.aspx?";
httpUrl = httpUrl + "vendorID="+paramsList[0]+
"&title="+paramsList[1]+
"&planTypeID=" +paramsList[2];
request.open("GET", httpUrl);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; Charset=utf-8");
request.send(null);
【问题讨论】:
-
在将参数值添加到 URL 之前,您需要使用
encodeURIComponent()对参数值进行编码。 -
你得到什么错误?
-
encodeURIComponent() 被我保存了
-
所以@Pointy 将其发布为答案..
标签: javascript utf-8 xmlhttprequest