prototype 中文参数乱码解决方案_prototype

WBOY
Release: 2016-05-16 18:41:59
Original
945 people have browsed it

在使用portotype,调用ajax方法时出现乱码,此时,获取页面中加入
可以试试;; Page.Response.Charset = "gb2312";
如果不奏效,有人提供另外解决方案:

复制代码代码如下:

request: function(url) {
this.url = url;
this.method = this.options.method;
this.encoding = this.options.encoding;
var params = this.options.parameters;
if(this.encoding.toUpperCase()=="UTF-8"){
encode=encodeURIComponent;
}else{
encode=escape;
}

在调用时,加上encoding: 'gb2312'
复制代码代码如下:

var myAjax = new Ajax.Updater(
"dvContent",
url,
{
method: 'get',
parameters: pars,
encoding: 'gb2312'
});

另外还有一种方案;无论web.config中是否是"gb2312",都可以奏效。
因为网站编码是gb2312。在使用prototype的ajax时遇到中文参数乱码的问题。
方法如下;
1.将参数用encodeURI()编码
复制代码代码如下:

var par;
par="param1="+"中文值"+"¶m2="+"其他值";
var url="server.aspx";
var myAjx=new Ajax.Request(url,{method: get',parameters: encodeURI(par) ,onComplete: submit});

2.接受端代码
复制代码代码如下:

NameValueCollection nvc= HttpUtility.ParseQueryString(Request.Url.Query, Encoding.UTF8);
string title = (nvc["param1"] == null) ? "" : nvc["param1"];//接受中文

给出一个完整的调用示例,
复制代码代码如下:

/**//*
Ajax企业名称是否存在检查
*/
function CheckCompanyExist()
{
var objtxtName=arguments[0];
var objBtnSubmit=arguments[1];
var objBtnCheck=arguments[2];
var currC_ID=arguments[3];
//alert($(arguments[0]).value);
var objtxtValue=$(arguments[0]).value;
$(objBtnSubmit).disabled=true;
if($F(objtxtName).trim())
{
$(objtxtName).disabled=!$(objtxtName).disabled;
var url="/tempAjaxService/";
var pars="module=CompanyExist&C_ID="+currC_ID+"&name="+objtxtValue;//$F(objtxtName);//objtxtValue;//
var myAjax = new Ajax.Request(url, {method: 'get', parameters: encodeURI(pars),onComplete : function() {
var txt = (''+arguments[0].responseText).evalJSON();
if(txt.Results==0||txt.Results==currC_ID)
{
//alert(''+arguments[0].responseText);
$(objBtnSubmit).value="提交我的企业信息";
$(objBtnSubmit).disabled=false;
alert("企业验证通过,您可以继续下一步操作");
}
else
{
$(objBtnSubmit).value="请先确认您的企业信息是否已存在本网中";
if(window.confirm('此企业已存在,想获得该公司管理权限,点击“确定”,了解详情!!\r\n如果不能打开窗口,请检查并取消您所用浏览器的“弹出窗口拦截”功能。 \n或在浏览器地栏中输入以下地址\r\nhttp://www.jb51.net/ZhengMing.aspx'))
window.open ('http://www.jb51.net/ZhengMing.aspx','newwindow','height=160,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
}
$(objtxtName).disabled=!$(objtxtName).disabled;
}});
}

Code
复制代码代码如下:

//Page.Response.Charset = "gb2312";
NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(Request.Url.Query, Encoding.UTF8);
Name=SQLParser.StringParse(nvc["name"]);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!