jquery的post数据,ashx出现中文乱码 最终 解决方案

来源:互联网 发布:美工刀片 编辑:程序博客网 时间:2024/04/19 11:41

类似这个方法,今天我做的一个ajax传值。中文接受时始终是乱码,偶然间,我把context.Request.QueryString[""]改成context.Request.Params["StudentName"];,把POST改成GET反而可以了了,太神奇。

jquery的Post数据的写法

复制代码 代码以下:

$(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文件中吸收参数的写法

string strStudentName = context.Request.Params["StudentName"];

留意:假如没有contentType:"application/x-www-form-urlencoded; charset=UTF-8",则context.Request.Params["StudentName"]是乱码。


原创粉丝点击