带有UTF-8错误的Http请求?

时间:2011-12-13 14:31:27

标签: javascript utf-8 xmlhttprequest

我必须使用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);

1 个答案:

答案 0 :(得分:0)

以下是我的评论的答案形式:错误可能与未经URL编码的参数值有关:

 httpUrl = httpUrl + "vendorID=" +
   encodeURIComponent(paramsList[0]) +
   "&title=" +
   encodeURIComponent(paramsList[1]) +
   "&planTypeID=" +
   encodeURIComponent(paramsList[2]);

这种编码(几乎可以肯定)将由服务器端框架透明地完成。