一般处理程序接受乱码问题
我在web.config的<system.web>节点下已经配置了
<globalization requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN"/>
function StopButton() {
document.getElementById(arguments[0]).disabled = true;
document.getElementById(arguments[0]).value = "提交(" + arguments[1] + ")";
if (--arguments[1] > 0) {
window.setTimeout("StopButton('" + arguments[0] + "'," + arguments[1] + ")", 1000);
}
if (arguments[1] <= 0) {
document.getElementById(arguments[0]).value = '提交';
document.getElementById(arguments[0]).disabled = false;
}
}
function SendComment() {
var commentuser = $("input#CommentUser").val().trim();
var commenttext = $("textarea#CommentText").val().trim();
if (commentuser == "" && commenttext == "") {
$("div#warning").html("<font color='red'>内容为空!<br />昵称为空!</font>");
return false;
}
if (commentuser == "") {
$("div#warning").html("<font color='red'>昵称为空!</font>");
return false;
}
if (commenttext == "") {
$("div#warning").html("<font color='red'>内容为空!</font>");
return false;
}
$("div#warning").html("");
$.ajax({
url: "addcomment.ashx?commentuser=" + commentuser + "&commenttext=" + commenttext,
type: "get",
success: function (data) {
if (data == "y") {
$("div#tishi").css({
background: "yellow",
"MARGIN-RIGHT": "auto",
"MARGIN-LEFT": "auto",
position: "absolute",
"z-index": 1,
left: "550px",
top: "400px"
});
$("div#tishi").html("<b>添加成功!</b>");
$("div#tishi").show(600);
//window.setInterval(function () { $("div#tishi").fadeOut(1000) }, 2000)
ShowComment();
$("input#CommentUser").val("");
$("textarea#CommentText").val("");
StopButton('CommentSubmit', 10);
}
}
});
}
$(document).ready(function () {
ShowComment();
});
<input type='button' class="postsubmit" id="CommentSubmit" value='提交' onclick="SendComment(1)" />
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request.QueryString["commentuser"] == null || context.Request.QueryString["commenttext"] == null)
{
context.Response.Write("parameter error");
}
else
{
string commentuser = context.Request.QueryString["commentuser"].ToString();
string commenttext = context.Request.QueryString["commenttext"].ToString();
Comment comment = new Comment()
{
Parentid = 1,
Commentuser = commentuser,
Commenttext = commenttext,
Commentreply = "",
Commentip = context.Request.UserHostAddress,
Commentdate = DateTime.Now
};
int n = CommentManager.AddComment(comment);
if (n > 0)
{
context.Response.Write("y");
context.Response.End();
}
else
{
context.Response.Write("n");
context.Response.End();
}
}
}
url: "addcomment.ashx?commentuser=" +escape( commentuser) + "&commenttext=" +escape( commenttext),
function ShowComment() {
$.ajax({
url: "Handler1.ashx?parentid=1&t=" + Math.random(),
type: "get",
success: function (data) {
$("div#comment").html(data);
}
});
}
<meta http-equiv="content-type" content="text/html;charset=gb2312">