繁体   English   中英

用ajax传递数据,用Request.Form[""]读取

[英]Passing data with ajax and read it with Request.Form[""]

我尝试将参数从js脚本传递到aspx.cs页面。 当我省略时:

contentType: "application/json; charset=utf-8"

在 ajax 请求中,我通过Request.Form["ORDER"]某事获得,例如{%7b%22ORDER_ID%22%3a126333%7d} 这意味着这个数据来到aspx.cs ,但它没有被解码。

没有内容类型

当我添加contentType我没有收到任何请求。

含内容类型

下面我附上请求。

它从读参数是重要Request.Form["ORDER"]aspx.cs ;

$.ajax({
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ ORDER_ID: orderKeyId }),
        dataType: "json",
        url: sUrl,
        success: function (data) {
            var s = 0;
        },
        error: function () {
            var s = 0;
        }
    });

根据@Rory McCrossan 的评论,以下 ajax 状态有效:

$.ajax({
    type: 'POST',
    contentType: "application/x-www-form-urlencoded",
    data: "ORDER_ID=" + encodeURIComponent(orderKeyId),
    url: sUrl,
    success: function (data) {
        var s = 0;
    },
    error: function () {
        var s = 0;
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM