有人知道这是怎么回事吗?我尝试将一个值从 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# 中为空。有谁知道这里出了什么问题?
最佳答案
在 POST 中传递数据时,数据不是传递到 Request.QueryString
中,而是传递到 Request.Form
中。尝试
newTest.Value = Request.Form["sState"];
我要更改的另一件事是 jQuery 调用 - 使用数据对象而不是字符串,例如:
$.ajax({
type: "POST",
url: "pgtest.aspx",
data: { sState: "VIC" },
success: function (msg) {
alert("Data Saved: " + msg);
}
});
关于c# - 无法将发布值从 ajax 传递到 .net c# 中的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972789/