ajax中contentType为application/json的用法

不使用contentType: "application/json",则data可以是对象

$.ajax({
  url: url,
  type: "post",
  datType: "json",
  data: { id: user_id },
  async: false,
  success: function () {}
});

使用contentType: "application/json",则data只能是json字符串

$.ajax({
  url: url,
  type: "post",
  datType: "json",
  contentType: "application/json"
  data: "{'id': " + user_id +"}",
  async: false,
  success: function () {}
});
上一篇 JavaScript原生和jQuery的ajax用法
下一篇 jQuery Cannot set property 'display' of undefined
目录
文章列表
1 Spring Security OAuth2 Redis 模式下认证服务器
Spring Security OAuth2 Redis 模式下认证服务器
2
React Native学习之在React Native中使用Flexbox
React Native学习之在React Native中使用Flexbox
3
Vue 中微信支付,显示WeiXinJSBridge is not defined的问题
Vue 中微信支付,显示WeiXinJSBridge is not defined的问题
4
Swift - 区间运算符
Swift - 区间运算符
5
在UltraEdit、Notepad++、EmEditor中使用正则表达式替换将字符串中的小写转换成大写
在UltraEdit、Notepad++、EmEditor中使用正则表达式替换将字符串中的小写转换成大写
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。