【问题标题】:XmlHttpRequest with asp.netXmlHttpRequest 与 asp.net
【发布时间】:2013-03-27 15:21:54
【问题描述】:

我尝试向我的 ashx 文件发送获取请求。但我遇到了字符问题。
问题是当我通过 firefox 或 crome 发送请求时没有问题,但是当尝试使用 IE 发送时,我无法
得到我发送的内容。我发送“Ç”字符但在服务器端我无法得到它。

myRequest.open("GET", "/Search.ashx?SearchText=" + search + "", true);
myRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
myRequest.send(null);

【问题讨论】:

  • 你试过myRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); 吗?
  • 是的,我做到了,但这是用于内容编码,我需要对 URL 进行编码
  • 试试看:var myEncodedUrl = "/Search.ashx?SearchText=" + encodeURIComponent(search); myRequest.open("GET", myEncodedUrl, true);

标签: javascript asp.net internet-explorer web xmlhttprequest


【解决方案1】:

您似乎没有使用 javascript 使用 encodeURIComponent 函数对“搜索”字符串进行编码。在 ashx 方面,您可以使用 HttpUtility.HTMLDecode 方法来解码您的字符串。

【讨论】:

  • 嗨,谢谢你的建议,但不要告诉我我是怎么钓到鱼的,给我一条鱼
【解决方案2】:

encodeURIComponent(search) 是答案。

【讨论】:

    猜你喜欢
    • 2012-01-29
    • 2010-11-01
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-03
    相关资源
    最近更新 更多