zoukankan      html  css  js  c++  java
  • ajax post data 获取不到数据,注意content-type的设置post/get

    因为之前一直用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是这样的:

    这种情况下,后台通过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是这样的:

     

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

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

  • 相关阅读:
    爬虫大作业
    熟悉常用的HDFS操作
    数据结构化和保存
    爬取全部校园新闻
    爬取校园新闻
    Google布隆过滤器
    谷歌json和对象转换
    postgresql和postgis
    json和实体类互相转换
    Linux安装docker-compose
  • 原文地址:https://www.cnblogs.com/25miao/p/6831609.html
Copyright © 2011-2022 走看看