关于 ajax Content-Type 的问题 贼拉有用的!!!
来源:互联网 发布:股票收益计算软件 编辑:程序博客网 时间:2024/05/21 08:42
之前我写ajax根本就没有去关注响应头什么的 只是很简单的用而已 后来发现其实没那么简单
Content-Type 指的是发送至服务器的数据类型,而data-Type定义的是服务器返回的数据类型.此处应有图
上面那个红圈是Content-Type控制的数据类型 ,下面那个红圈是data-Type控制的数据类型
如果不指定ContentType,则一般情况默认为text/html,表单数据默认为application/x-www-form-urlencoded。
如果是 type: “GET”的话,以上三种都可以,因为GET类型的参数是紧跟在url后面,与Content-Type无关
如果是 type: “POST”的话,data数据是由form表单提交,此时就必须把Content-Type设为application/x-www-form-urlencoded(也可以不指定content-Type,因为表单提交默认是application/x-www-form-urlencoded),否则后台是无法接收到数据的。
contentType数据类型的不同 data里面所传递的数据类型也不同
- 如果是不使用contentType: “application/json”则data可以是对象 *
$.ajax({ type: "GET", url: "/SmartStrip/InsertRow/GetDeviceList", data: { }, dataType: 'JSON', success: function (data) { console.log(data); }, error: function () { }, })
- 如果是使用contentType: “application/json”则data只能是json形式的字符串,需自行拼接
$.ajax({ type: "POST", beforeSend: function (request) { request.setRequestHeader("Authorization",Authorization); }, url: url, dataType: 'JSON', contentType: "application/json", data: '{' + '"name":"' + name + '",' + '"idsn":"' + idsn + '",' + '"brand":"' + brand + '",' + '"model":"' + model + '",' + '"pid":"' + pid + '",' + '"baseID":"' + baseID + '",' + '"areaID":"' + areaID + '"' + '}', success: function (data) { console.log(data); }, error: function () { }, })
哇咔咔 ~~ 写完了~
阅读全文
1 0
- 关于 ajax Content-Type 的问题 贼拉有用的!!!
- 不同Content Type下的$.ajax请求
- 关于Content-Type的一张表
- 关于Content-Type的一张表
- 关于Content-Type的一张表
- 关于Content-Type的一张表.
- 关于Content-Type的全部类型
- 关于SpringMVC content-type的那些事
- 一个content-type引发的问题
- java URLConnection中的 Content-Type 与 ajax 的contentType
- Content-type 的说明
- Content-type 的说明
- 各类的Content-type
- Content-type 的说明
- Content-Type的类型
- MIME的content-type
- content-type的作用
- 常见的content-type
- Tomcat目录配置
- 设置firefox每次访问网页时检查所存网页的较新版本
- 未来时代java未来的路
- linux 登录 oracle,mysql
- Windows下OpenLDAP的安装及使用
- 关于 ajax Content-Type 的问题 贼拉有用的!!!
- js删除url参数并返回url
- krpano——添加背景音乐
- web页面判断是否安装某app,从web启动app应用
- 一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
- 安装基于HTML5的SSH工具GateOne (by quqi99)
- nvm的安装及使用
- 模拟实现strcpy,memcpy,memovestrcat,
- 数据结构总结之拓扑排序