在使用portotype,调用ajax方法时出现乱码,此时,获取页面中加入
可以试试;; Page.Response.Charset = "gb2312";
如果不奏效,有人提供另外解决方案:
Code
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",都可以奏效。参考http://www.okajax.com/a/200904/prototype_utf8.html
方法如下;
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"];//接受中文