【问题标题】:Unable to get Post data无法获取发布数据
【发布时间】:2014-05-21 16:36:32
【问题描述】:

JS代码:

function save( ref, text){
            $.post("save.aspx", {cc:"us", ref:ref, text:text}, function(data){
                $("[data-ref='"+ref+"'] .loader").animate({opacity:0},500,function(){
                    $(this).parent().removeClass("saving");
                    $(this).remove();
                });

            });
        }

CS文件代码:

public partial class save : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       // $_REQUEST['cc'];
       // HttpContext.Current.Response
        string strcc = Request.Form["cc"];
        string strRef = Request.Form["ref"];
        string strtext =Request.Form["text"];
    }
}

无法获取从 JS 代码传递到下一页的值,我在这里做错了什么?

【问题讨论】:

  • 如果你把你的帖子参数放在引号之间会发生什么:{"cc":"us", "ref":ref, "text":text}
  • @ashish 我认为你是否引用并不重要。
  • @Ashish 我也试过了,但没有帮助

标签: c# jquery


【解决方案1】:

您的代码很好。我几乎可以肯定 ASPX 页面代码在 JS 函数调用它之前执行。你可以用Fiddler追踪这个

【讨论】:

  • 用提琴手检查,在 IE 中我找到这个 POST localhost:41162/Admin/save.aspx HTTP/1.1 Accept: / Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: localhost:41162/Admin/translate.aspx?cc=af Accept-Language: en-IN Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; MDDSJS) 主机:localhost:41162 内容长度:0 DNT:1 连接:Keep-Alive Pragma: no-cache
  • 并在 Chrome POST localhost:41162/Admin/save.aspx HTTP/1.1 主机:localhost:41162 连接:keep-alive 内容长度:49 接受:/ 来源:localhost:41162 X-请求方式:XMLHttpRequest 用户代理:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: localhost:41162/Admin/translate.aspx?cc=af Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 cc=us&ref=msg_share_title&text=Sharing+is+caringr
  • Chrome 能够获取数据但在 IE 中没有任何原因?
  • 哪个页面在调用 localhost:41162/Admin/save.aspx?您是否在另一个页面或 save.aspx 上有该 JS 脚本?
  • 那个脚本在不同的页面/admin/translate.aspx
猜你喜欢
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 1970-01-01
  • 1970-01-01
  • 2016-04-17
  • 2012-11-23
  • 2015-03-29
相关资源
最近更新 更多