无法将 post 值从 ajax 传递到 .net c# 中的页面
有谁知道这是怎么回事?我尝试将值从 ajax 传递到 .aspx,但不知何故,该值似乎没有成功传递。
以下是我的代码:
$.ajax({
type: "POST",
url: "pgtest.aspx",
data: "sState=VIC",
success: function (msg) {
alert("Data Saved: " + msg);
}
});
这是我的 .net c# 中的代码:
newTest.Value = Request.QueryString["sState"];
不知何故, for Request.QueryString["sState"] 在 .net c# 中为空。有谁知道这里出了什么问题?
Does anyone know what is it going on here? I have try to pass a value from ajax to .aspx, but somehow the value seem doesn't pass over successfully.
Following is my code:
$.ajax({
type: "POST",
url: "pgtest.aspx",
data: "sState=VIC",
success: function (msg) {
alert("Data Saved: " + msg);
}
});
and this is my code inside my .net c#:
newTest.Value = Request.QueryString["sState"];
Somehow the for Request.QueryString["sState"] is empty in .net c#. Does anyone know what is going wrong here ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 POST 中传递数据时,数据不是在
Request.QueryString
中传递,而是传递到Request.Form
中。尝试我要更改的另一件事是 jQuery 调用 - 使用数据对象而不仅仅是字符串,例如:
When passing data in POST, the data is not passed in
Request.QueryString
, it's passed intoRequest.Form
instead. TryAnother thing I'd change is the jQuery call - use a data object instead of just a string, a such:
Request.QueryString
仅适用于 GET 请求。对于 POST 请求,您需要Request.Form
。另请参阅:在 C#/ASP.NET 中获取 POST 数据Request.QueryString
is for GET requests only. For POST requests, you needRequest.Form
. See also: Get POST data in C#/ASP.NET您需要使用 GET 请求,因为它本质上很轻,但安全性也较低,并且它是在查询字符串中传递的。:
现在您将获得以下值:
You need to use GET request as it is light in nature but less secured too and it is passed in querystring.:
Now you will get below values: