龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

jquery使用ajax传内容到asp.net乱码解决

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
jquery的ajax传递参数都是转换成utf-8编码的,所以有发送前加上url编码函数escape(),之后asp.net接收处理为Server.UrlDecode(Request[参数]) 例子如下: %@ Page Language="C#" AutoEventWireup="true" CodeBehind

jquery的ajax传递参数都是转换成utf-8编码的,所以有发送前加上url编码函数escape(),之后asp.net接收处理为Server.UrlDecode(Request[参数])

例子如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="DYJ.stockSms.test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript" src="jq.js"></script>
    <script>
        function hq() {
            $.post("test.aspx", { "stock": escape("www结合中文测试123") }, function(data) {
            $("#show").html(data);
                }
            );  
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type=button value="测试" onclick="hq();" runat="server" />
    </div>
    <span id="show"></span>
    </form>
</body>
</html>

后台代码:

        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request["stock"] != null)
            {
                Response.Expires = -1;
                Response.Write(Server.UrlDecode(Request["stock"]));
                Response.End();
            }
        }

精彩图集

赞助商链接