无法从阿贾克斯在.NET C#通过岗位价值转移到页岗位、价值、转移到、阿贾克斯

2023-09-06 22:07:50 作者:心上的旧疤べ

没有人知道它是什么回事?我也试图通过值从阿贾克斯为.aspx,但不知何故价值似乎并没有越过成功。

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.

以下是我的code:

  $.ajax({
      type: "POST",
      url: "pgtest.aspx",
      data: "sState=VIC",
      success: function (msg) {
          alert("Data Saved: " + msg);
      }
  });

这是在我的.NET C#我code:

and this is my code inside my .net c#:

newTest.Value = Request.QueryString["sState"];

不知何故,为的Request.QueryString [sState]是空的。NET C#。有谁知道是怎么回事错在这里?

Somehow the for Request.QueryString["sState"] is empty in .net c#. Does anyone know what is going wrong here ?

推荐答案

当在POST传递数据,数据是不是在的Request.QueryString 过去了,它传递到的Request.Form 代替。尝试

When passing data in POST, the data is not passed in Request.QueryString, it's passed into Request.Form instead. Try

newTest.Value = Request.Form["sState"];

另一件事我会改变的是jQuery的电话 - 只使用一个字符串的数据对象,而不是一个这样的:

Another thing I'd change is the jQuery call - use a data object instead of just a string, a such:

$.ajax({
      type: "POST",
      url: "pgtest.aspx",
      data: { sState: "VIC" },
      success: function (msg) {
          alert("Data Saved: " + msg);
      }
});