Recently, a small open-source project jeebookstore was launched using extjs + ashx.
I didn't feel any problem during my previous tests in English. When I had a Chinese character last weekend, I was harassed for a weekend due to garbled code.
At the beginning is formpanel sent data to ashx when garbled, Google such a problem is quite a lot, all JS and HTML into the UTF-8, then the call js html settings for UTF-8 encoding, of course ASP request and response keep the default UTF-8, Firefox on the No garbled problem.
Try again IE and find that there is no problem with the data in formpanel, but the Chinese characters passed through URL parameters are still incorrect. Try to use the escape, encodeuri, and encodeuricomponent functions in sequence to encode the URL.
Multiple tests show that if you use the Params attribute of the form. Submit function to pass parameters and the method is get, the performance in IE is normal. For example:
URL: ashx/AddFile. ashx? Name = China & Path =/China
Form. Submit ({
URL: 'ashx/AddFile. ashx ',
Method: 'get ',
Params :{
Name: 'China ',
Path: '/China ';
}
})
Check action. code of the submit class. It is found that extjs uses Params in submit to splice the code into the above URL. The reason why there is no garbled code is that each value is encoded separately, the encoding function is exactly encodeuricomponent, but it does not directly call the whole URL as I did before.
This is another option. The unreasonable problem is often the function call problem.
At last, both IE and Firefox can correctly process Chinese characters, but the file name for downloading files has become messy in Firefox. Of course, it is not too messy, only % E7 % E9 is displayed.
Check and find that I use server when returning the file name. urlencode to the file name to do the UTF-8 encoding, if the direct return of the file name Firefox normal, but IE also changed garbled, this time is a thorough garbled. It seems that Firefox uses the ISOxxxx-1 encoding for file name resolution, rather than the encoding type recorded in the HTTP header. After studying Google + for a long time, it seems that there is no good solution, so I had to make a browser branch in ashx, that is:
Httpbrowsercapabilities BC = httpcontext. Current. Request. browser;
If (
BC. browser = "ie ")
_ Response. addheader ("content-disposition ",
"Attachment; filename =" + httputility. urlencode (_ filename,
System. Text. encoding. utf8 ));
Else
_ Response. addheader ("content-disposition", "attachment; filename =" + _ filename );
The code is simple, but there is still an episode. Because ashx and context. Request do not have the browser attribute, httpcontext. Current. Request. browser must be used for normal calls.
Finally, the final dust settled, although there are still Firefox download file names included; the file name will be truncated and other issues, but stay next time.