[英]Passing data with ajax and read it with Request.Form[""]
I try to pass parameters into aspx.cs
page from js
script.我尝试将参数从
js
脚本传递到aspx.cs
页面。 When I omit:当我省略时:
contentType: "application/json; charset=utf-8"
in ajax request I get by Request.Form["ORDER"]
sth like {%7b%22ORDER_ID%22%3a126333%7d}
.在 ajax 请求中,我通过
Request.Form["ORDER"]
某事获得,例如{%7b%22ORDER_ID%22%3a126333%7d}
。 It means that this data comes to aspx.cs
, but it is not decoded.这意味着这个数据来到
aspx.cs
,但它没有被解码。
When I add contentType
I get nothing in request.当我添加
contentType
我没有收到任何请求。
Below I attach request.下面我附上请求。
It is important to read parameters from Request.Form["ORDER"]
in aspx.cs
;它从读参数是重要
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;
}
});
According to @Rory McCrossan comment, below ajax state worked:根据@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.