最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery向.ashx文件post中文亂碼問題的解決方法

 更新時間:2011年03月28日 22:29:07   作者:  
jquery向.ashx文件post中文亂碼問題的解決方法,需要的朋友可以參考下。
1.我的環(huán)境:vs2005,未裝SP1補丁,不能創(chuàng)建Web應(yīng)用程序,只能創(chuàng)建網(wǎng)站;jquery版本1.5.1

2.web.config中的相關(guān)配置

<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>

3.jquery的Post數(shù)據(jù)的寫法
復(fù)制代碼 代碼如下:

$(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);
}
});
});
});

其中StudentName是中文

4.在.ashx文件中接收參數(shù)的寫法

string strStudentName = context.Request.Params["StudentName"];
注意:如果沒有contentType:"application/x-www-form-urlencoded; charset=UTF-8",則context.Request.Params["StudentName"]是亂碼。
經(jīng)過在.ashx中跟蹤context.Request.ContentEncoding,可知jquery所post過來的數(shù)據(jù)采用的是gb2312編碼,可能context.Request在接收到數(shù)據(jù)時默認采用utf-8進行解碼,但是jquery在Post數(shù)據(jù)的時候卻不是用的utf-8才導(dǎo)致.ashx的context.Request.Params["StudentName"]顯示為亂碼。
感覺比較奇怪的現(xiàn)象:
現(xiàn)象1:在不添加contentType:"application/x-www-form-urlencoded; charset=UTF-8",的情況下,在.ashx文件中使用下面的語句卻可以正確顯示字符串:
復(fù)制代碼 代碼如下:

StreamReader steamRd = new StreamReader(HttpContext.Current.Request.InputStream);
string strPostData = steamRd .ReadToEnd();
strPostData =HttpUtility.UrlDecode(strPostData, Encoding.GetEncoding("utf-8"));

現(xiàn)象2:將web.config中的相關(guān)配置改為
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
之后,不管是否加上contentType:"application/x-www-form-urlencoded; charset=UTF-8",后臺的.ashx文件接收到的參數(shù)仍然是亂碼。修改web.config之后網(wǎng)站編譯的很慢且運行的也很慢。

參考文章:
http://www.fzitv.net/article/26658.htm
http://www.fzitv.net/article/26659.htm

相關(guān)文章

最新評論

布拖县| 丰县| 汝南县| 盈江县| 堆龙德庆县| 万州区| 竹山县| 平定县| 津市市| 丹阳市| 克拉玛依市| 沙田区| 辽源市| 靖远县| 铜梁县| 庆城县| 友谊县| 新乡县| 修武县| 隆林| 德清县| 新晃| 平阳县| 武定县| 镇沅| 资中县| 罗城| 湾仔区| 八宿县| 秀山| 景东| 恩平市| 丹阳市| 昌吉市| 新田县| 明光市| 沧州市| 合水县| 临江市| 新龙县| 邢台县|