Prototype Chinese parameter garbled Solution

Source: Internet
Author: User

Garbled characters occur when calling the ajax method using portotype. In this case, add

You can try; Page. Response. Charset = "gb2312 ";

If it does not work, someone provides another solution:

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;
}

When calling, add encoding: 'gb2312'
Var myAjax = new Ajax. Updater (
"DvContent ",
Url,
{
Method: 'get ',
Parameters: pars,
Encoding: 'gb2312'
});

 
There is also a solution; whether the web. config is "gb2312" or not, it can work. Reference http://www.okajax.com/a/200904/prototype_utf8.html

The method is as follows;

1. encode the parameter with encodeURI ()

Var par;
Par = "param1 =" + "Chinese value" + "& param2 =" + "other values ";
Var url = "server. aspx ";
Var myAjx = new Ajax. Request (url, {method: get ', parameters: encodeURI (par), onComplete: submit });

 2. receiver code

NameValueCollection nvc = HttpUtility. ParseQueryString (Request. Url. Query, Encoding. UTF8 );
String title = (nvc ["param1"] = null )? "": Nvc ["param1"]; // Chinese

A complete call example is provided,

Code
/**//*
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 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 = "submit my Enterprise Information ";
$ (ObjBtnSubmit). disabled = false;
Alert ("Enterprise verification passed, you can continue the Next Step ");
}
Else
{
$ (ObjBtnSubmit). value = "check whether your enterprise information already exists in this network ";
If (window. confirm ('this enterprise already exists. To obtain the management permission of this company, click "OK" to learn more !! \ R \ n if the window cannot be opened, check and cancel the pop-up window blocking function of your browser. \ R \ n or enter the following address in the browser field \ r \ nhttp: // www.agronet.com.cn/ZhengMing.aspx '))
Window. open ('HTTP: // response ');
}
$ (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"]);

For more information about non-Ajax, see here.

Http://www.cnblogs.com/downmoon/archive/2007/12/30/1021140.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.