When using portotype, garbled code appears when calling ajax method. At this time, add the page to the get
You can try;; = "gb2312";
If it doesn't work, someone else provides an additional solution:
request: function(url) {
= url;
= ;
= ;
var params = ;
if(()=="UTF-8"){
encode=encodeURIComponent;
}else{
encode=escape;
}
When calling, add encoding: 'gb2312'
var myAjax = new (
"dvContent",
url,
{
method: 'get',
parameters: pars,
encoding: 'gb2312'
});
There is another solution; it can work regardless of whether it is "gb2312".
Because the website encoding is gb2312. When using ajax with prototype, we encountered the problem of garbled Chinese parameters.
The method is as follows;
1. Encode the parameters with encodeURI()
var par;
par="param1="+"Chinese value"+"¶m2="+"Other values";
var url="";
var myAjx=new (url,{method: get',parameters: encodeURI(par) ,onComplete: submit});
2. Accept the code
NameValueCollection nvc= (, Encoding.UTF8);
string title = (nvc["param1"] == null) ? "" : nvc["param1"];//Accept Chinese
Given a complete call example,
/**//*
Check whether the Ajax enterprise name exists
*/
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 (url, {method: 'get', parameters: encodeURI(pars),onComplete : function() {
var txt = (''+arguments[0].responseText).evalJSON();
if(==0||==currC_ID)
{
//alert(''+arguments[0].responseText);
$(objBtnSubmit).value="Submit my business information";
$(objBtnSubmit).disabled=false;
alert("Enterprise verification is passed, you can continue to the next step");
}
else
{
$(objBtnSubmit).value="Please confirm whether your company information already exists on this website";
if('This enterprise already exists. If you want to obtain management permissions of the company, click "OK" to learn more!!\r\nIf the window cannot be opened, please check and cancel the "pop-up blocking" function of the browser you are using.\r\nOr or enter the following address in the browser's groundbar\r\nhttps:///'))
('https:///','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
// = "gb2312";
NameValueCollection nvc = (, Encoding.UTF8);
Name=(nvc["name"]);
You can try;; = "gb2312";
If it doesn't work, someone else provides an additional solution:
Copy the codeThe code is as follows:
request: function(url) {
= url;
= ;
= ;
var params = ;
if(()=="UTF-8"){
encode=encodeURIComponent;
}else{
encode=escape;
}
When calling, add encoding: 'gb2312'
Copy the codeThe code is as follows:
var myAjax = new (
"dvContent",
url,
{
method: 'get',
parameters: pars,
encoding: 'gb2312'
});
There is another solution; it can work regardless of whether it is "gb2312".
Because the website encoding is gb2312. When using ajax with prototype, we encountered the problem of garbled Chinese parameters.
The method is as follows;
1. Encode the parameters with encodeURI()
Copy the codeThe code is as follows:
var par;
par="param1="+"Chinese value"+"¶m2="+"Other values";
var url="";
var myAjx=new (url,{method: get',parameters: encodeURI(par) ,onComplete: submit});
2. Accept the code
Copy the codeThe code is as follows:
NameValueCollection nvc= (, Encoding.UTF8);
string title = (nvc["param1"] == null) ? "" : nvc["param1"];//Accept Chinese
Given a complete call example,
Copy the codeThe code is as follows:
/**//*
Check whether the Ajax enterprise name exists
*/
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 (url, {method: 'get', parameters: encodeURI(pars),onComplete : function() {
var txt = (''+arguments[0].responseText).evalJSON();
if(==0||==currC_ID)
{
//alert(''+arguments[0].responseText);
$(objBtnSubmit).value="Submit my business information";
$(objBtnSubmit).disabled=false;
alert("Enterprise verification is passed, you can continue to the next step");
}
else
{
$(objBtnSubmit).value="Please confirm whether your company information already exists on this website";
if('This enterprise already exists. If you want to obtain management permissions of the company, click "OK" to learn more!!\r\nIf the window cannot be opened, please check and cancel the "pop-up blocking" function of the browser you are using.\r\nOr or enter the following address in the browser's groundbar\r\nhttps:///'))
('https:///','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
Copy the codeThe code is as follows:
// = "gb2312";
NameValueCollection nvc = (, Encoding.UTF8);
Name=(nvc["name"]);