Javascript ajax aspx脚本参数波兰(特殊)字符
我正在使用ajax调用aspx服务器端脚本来发送电子邮件。以下是我的ajax发送函数:Javascript ajax aspx脚本参数波兰(特殊)字符,javascript,asp.net,ajax,character-encoding,Javascript,Asp.net,Ajax,Character Encoding,我正在使用ajax调用aspx服务器端脚本来发送电子邮件。以下是我的ajax发送函数: //global variables------------------------------------------------------- var html_dir = "/Html/" var net_dir = "/Net/" //ajax request----------------------------------------------------------- function aja
//global variables-------------------------------------------------------
var html_dir = "/Html/"
var net_dir = "/Net/"
//ajax request-----------------------------------------------------------
function ajaxRequest(url, cfunc, asynch)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
{
response = new XMLHttpRequest();
}
// code for IE6, IE5
else
{
response = new ActiveXObject("Microsoft.XMLHTTP");
}
//send request
response.onreadystatechange = cfunc;
response.open("GET", url, asynch);
response.send();
}
//-----------------------------------------------------------------------
ajaxRequest(net_dir + "SendForm.aspx?emailBody=" + emailBody, formSent, true);
我是这样运行这个函数的:
//global variables-------------------------------------------------------
var html_dir = "/Html/"
var net_dir = "/Net/"
//ajax request-----------------------------------------------------------
function ajaxRequest(url, cfunc, asynch)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
{
response = new XMLHttpRequest();
}
// code for IE6, IE5
else
{
response = new ActiveXObject("Microsoft.XMLHTTP");
}
//send request
response.onreadystatechange = cfunc;
response.open("GET", url, asynch);
response.send();
}
//-----------------------------------------------------------------------
ajaxRequest(net_dir + "SendForm.aspx?emailBody=" + emailBody, formSent, true);
它工作得很好,但我对波兰字符(łąąę等)有问题。在电子邮件和SendForm.aspx脚本(调试时)中,存在一些奇怪的字符,而不是波兰语字母。我怎样才能修好它 我以前也遇到过同样的问题。您可以将特殊字符替换为“-”或“,”。收到回复后,请使用特殊字符更新字符串并发送邮件 它可能会对您有所帮助。您很可能需要输入
emailBody
参数:
ajaxRequest(net_dir + "SendForm.aspx?emailBody=" + encodeURIComponent(emailBody), formSent, true);
那就是
encodeURIComponent("łńóąę") === "%C5%82%C5%84%C3%B3%C4%85%C4%99"
在url中使用是安全的
在服务器端,如果未自动完成,则需要对其进行解码,然后:
string emailBody = HttpUtility.UrlDecode( Request.QueryString["emailBody"],
Encoding.UTF8 );
//Javascript's encodeURIComponent is always UTF8
服务器响应的输出使用哪个字符集?它应该是一些Unicode字符集,因为JS使用UCS-2。你能解释一下在哪里检查它吗?我正在使用Visual Studio 2012构建和运行我的页面。我对ASP开发一无所知。但是,如果我甚至不知道要发送哪个字符集,也不知道如何在您的环境中检查它,我假设这就是错误。谢谢您的回答,我会检查它。