首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

asp.net后台如何获取ajax提交的数据

2013-07-08 
asp.net后台怎么获取ajax提交的数据本帖最后由 showbo 于 2013-04-20 16:42:44 编辑$.ajax({type: Post,

asp.net后台怎么获取ajax提交的数据
本帖最后由 showbo 于 2013-04-20 16:42:44 编辑  

$.ajax({
                type: "Post",
                //           url: "WebForm1.aspx/SayHello",  
                url: "WebForm1.aspx",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{'str':'我是','str2':'XXX'}",
                success: function (data) {
                   //返回的数据用data.d获取内容     
                    alert(data.d);
                },
               error: function (err) {
                   alert(err);
                }
            });

后台:
 protected void Page_Load(object sender, EventArgs e)
        {
            string a = Context.Request["str"];
            string b = Request["str"];
            string c = Request.Form["str"];
            string d = Request.QueryString["str"];
        }

都获取不到,求解。。 ASP.NET Ajax juqery
[解决办法]
//data: "{'str':'我是','str2':'XXX'}",
//==>
data: {'str':'我是','str2':'XXX'},


指定了这个dataType: "json",动态页要返回标准json格式的字符串,要不也会执行error回调

怪异模式的json字符串jquery1.4+也会执行error,需要注意一下
[解决办法]
前台:
 $.ajax({
                                type: "POST",


                                url: "contact_story.ashx",
                                data: { shopname: shopname },
                                beforeSend: function() {
                                    //do nothing 
                                }
                            })


后台:
string shopname = context.Request["shopname"];

我一般是这样写的.. 希望对你有帮助吧

热点排行