jpx中的jQuery POST数据页面 [英] jquery POST data in aspx page

查看:107
本文介绍了jpx中的jQuery POST数据页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下代码将数据发布到我的aspx文件中:

I post data to my aspx file qith the following code:

 $.ajax({
            type: 'POST',
            url: "Ajax_Text.aspx?rand=" + myRand
                                        + "&id=" + $(".articleID").attr('title')
                                        + "&text=" + $("#text").val(),
            cache: false,
            beforeSend: function () {

            },
            success: function (data) {
                alert(data); 
            }
        });

为什么我使用以下代码捕获文本值

Why i catch the text value by using the following code

 string text = "";

            if (!String.IsNullOrEmpty(Request.QueryString["text"]))
            {
                text = Request.QueryString["text"].ToString();
            }
            else
            {
                text = "";
            }

而不是此代码:

string text = "";

            if (!String.IsNullOrEmpty(Request.Form["text"]))
            {
                text = Request.Form["text"].ToString();
            }
            else
            {
                text = "";
            }

那是为什么?我希望Request.Form可以在我通过jquery发布数据时正常工作!有什么想法吗?

Why is that? I expected Request.Form to work as i post data with jquery! Any ideas?

我怀疑问题是我在url参数中输入了我的输入.也许我应该将其放在数据参数中,但这意味着它将成为json请求!

I suspect that the problem is that i have my input in the url parameter. Maybe i should put it to a data parameter but that means it will become a json request!

推荐答案

POST数据不以查询字符串的形式发送,而是添加到请求正文中.尝试以下代码:

POST data are not send in query string but added to the request body. Try this code:

$.ajax({
        type: 'POST',
        url: "Ajax_Text.aspx",
        data: {'rand': myRand, 'id': $(".articleID").attr('title'), 'text': $("#text").val()},
        cache: false,
        beforeSend: function () {

        },
        success: function (data) {
            alert(data); 
        }
    });

这篇关于jpx中的jQuery POST数据页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆