因为之前一直用jQuery ajax get的方式传递参数, 默认没有设置过 contentType 的值。

  $.ajax({
               url: "/yuanjin/jianxiang",
               //contentType: "application/json; charset=utf-8",
                data: { username: username, cardnumber: cardnumber },
                type: "post",
                dataType: 'json',
                success: function (data) {
                    $.each(data, function (commentIndex, comment) {
                    });
                    $('#resText').html("");
                }
            });

 这时,在谷歌浏览器里看header是这样的:

ajax post data 获取不到数据,注意content-type的设置post/get

 

这种情况下,后台通过Request.Form[""]可以获取到值

而添加contentType后

   $.ajax({
               url: "/yuanjin/jianxiang",
               contentType: "application/json; charset=utf-8",
                data: { username: username, cardnumber: cardnumber },
                type: "post",
                dataType: 'json',
                success: function (data) {
                    $.each(data, function (commentIndex, comment) {
                    });
                    $('#resText').html("");
                }
            });

  这时,在谷歌浏览器里看header是这样的:

 ajax post data 获取不到数据,注意content-type的设置post/get

 这样的话,后台通过Request.Form[""]就获取不到了。

因此不要随意设置Content-Type的值

 

相关文章:

  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2021-05-20
  • 2022-12-23
猜你喜欢
  • 2021-10-25
  • 2022-02-21
  • 2021-09-16
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-02-23
相关资源
相似解决方案