1. My environment: VS2005, not installed SP1 patches, cannot create Web applications, can only create Web sites; jquery version 1.5.1
Related Configuration in 2.web.config
<globalization requestencoding= "gb2312" responseencoding= "gb2312"/>
The writing of 3.jquery post data
Copy Code code as follows:
$ (document). Ready (function () {
$ ("#btnSend"). Click (function () {
$.ajax ({
Type: "POST",
URL: "Precisionahandle.ashx",
ContentType: "application/x-www-form-urlencoded; Charset=utf-8 ",
Data: {"StudentID": $ ("#LblStudentId"). attr ("innertext"), "Studentname": $ ("#LblStudentName"). attr ("innertext"), " Studentage ": $ (" #txtStudentAge "). attr (" value ")},
Success:function (HTML) {
$ ("#TabContainer"). HTML (HTML);
}
});
});
});
Where Studentname is Chinese
4. How to receive parameters in a. ashx file
String strstudentname = context. request.params["Studentname"];
Note: If there is no contenttype: "application/x-www-form-urlencoded; Charset=utf-8 ", then the context. request.params["Studentname"] is garbled.
After tracking context.Request.ContentEncoding in. ASHX, you can see that the data that jquery has posted is gb2312 encoding, which may context.request be decoded by default Utf-8 when receiving data, but jquery The post data is not used utf-8 to cause. ashx context.request.params["Studentname" is displayed as garbled.
A phenomenon that feels rather strange:
Phenomenon 1: In not adding contenttype: "application/x-www-form-urlencoded;" Charset=utf-8 ", in the case where the following statement is used in the. ashx file, the string can be displayed correctly:
Copy Code code as follows:
StreamReader STEAMRD = new StreamReader (HttpContext.Current.Request.InputStream);
String strpostdata = Steamrd. ReadToEnd ();
Strpostdata =httputility.urldecode (Strpostdata, encoding.getencoding ("Utf-8"));
Phenomenon 2: Change the related configuration in web.config to
<globalization requestencoding= "Utf-8" responseencoding= "Utf-8"/>
After that, whether or not to add ContentType: "application/x-www-form-urlencoded; Charset=utf-8 ", the background of the. ashx file received the parameters are still garbled. After modifying the web.config, the site compiles slowly and runs slowly.
Reference articles:
Http://www.jb51.net/article/26658.htm
Http://www.jb51.net/article/26659.htm