//写在前面的话//contentType 和data是一对,data是什么类型是由contentType指定的,而dataType只是后台返回值的类型$("#postjson").click(function () {var json = JSON.stringify({ userid: "admin", password: "admin", test: "good" });var json2 = "{userid: 'admin', password: 'admin', test: 'good'}";$.ajax({type: "post",dataType: "json",//这里是后台返回值的类型contentType: 'application/json',//这是ajax传进去的数据类型,对应下面的datadata: json2,//json  和json2是一样的 一种是手动拼出来的,一种是生成的第一种会省事url: "/home/PostJson",//url: "/home/PostJson2",后台中一个是实体接收一个是原始参数接收success: function (data) {alert(data.userid + " " + data.password + " " + data.test);}});});$("#postkeyvalue").click(function () {$.ajax({type: "post",dataType: "json",contentType: 'application/x-www-form-urlencoded',//当ajax没有设置这个值时,默认就是这个data: { userid: "admin", password: "admin", test: "good"},url: "/home/PostKeyValue",//url: "/home/PostKeyValue2",后台中一个是实体接收一个是原始参数接收success: function (data) {alert(data.userid + " " + data.password + " " + data.test);}});});$("#postxml").click(function () {$.ajax({type: "post",dataType: "json",//contentType: 'text/plain',//这三种是一样的//contentType: 'text/xml',contentType: 'text/html',data: "<note><to>Tove</to></note>",url: "/home/PostXml",success: function (data) {alert(data);}});});
/// <summary>/// 实体接收/// </summary>/// <param name="p"></param>/// <returns></returns>[HttpPost]public ActionResult PostJson(Person p){return Json(new { p.userid, p.password, p.test });}/// <summary>/// 原始参数接收/// </summary>/// <param name="userid"></param>/// <param name="password"></param>/// <param name="test"></param>/// <returns></returns>[HttpPost]public ActionResult PostJson2(string userid, string password, string test){return Json(new { userid, password, test });}/// <summary>/// 实体接收/// </summary>/// <param name="p"></param>/// <returns></returns>[HttpPost]public ActionResult PostKeyValue(Person p){return Json(new { p.userid, p.password, p.test });}/// <summary>/// 原始参数接收/// </summary>/// <param name="userid"></param>/// <param name="password"></param>/// <param name="test"></param>/// <returns></returns>[HttpPost]public ActionResult PostKeyValue2(string userid, string password, string test){return Json(new { userid, password, test });}[HttpPost]public ActionResult PostXml(){StreamReader sr = new StreamReader(this.Request.InputStream);string a = sr.ReadToEnd();sr.Close();return Json(a);}

ajax contentType相关推荐

  1. $.ajax() contenttype,$.ajax 中的contentType类型

    前言 今天在搞项目的时候遇到一个问题,$.ajax 设置数据类型 applicaiton/json以后,服务器端(express)就拿不到数据,遂解决后将问题以及问题缘由整理下来.jquery 正文 ...

  2. jQuery ajax contentType processData 笔记

    contentType contentType 默认:'application / x-www-form-urlencoded; charset = UTF-8' 类型:Boolean或者String ...

  3. contenttype文件ajax_jquery ajax contentType设置

    默认get方法没有contentType,post方法的contentType为:application/x-www-form-urlencoded; charset=UTF-8 (1) 设置成app ...

  4. ajax contentType 设置

    $.ajax({type: "POST", // 提交方式 get/posturl: url,contentType: "application/json", ...

  5. 关于 ajax Content-Type 的问题 贼拉有用的!!!

    之前我写ajax根本就没有去关注响应头什么的 只是很简单的用而已 后来发现其实没那么简单 Content-Type 指的是发送至服务器的数据类型,而data-Type定义的是服务器返回的数据类型.此处 ...

  6. Ajax如何设置contenttype,jquery ajax contentType设置

    默认get方法没有contentType,post方法的contentType为:application/x-www-form-urlencoded; charset=UTF-8 (1) 设置成app ...

  7. ajax contenttype详解_jQuery ajax contentType processData 笔记

    contentType contentType 默认:'application / x-www-form-urlencoded; charset = UTF-8' 类型:Boolean或者String ...

  8. js ajax contenttype,ajax中设置contentType: application/json的作用(图文教程)

    这篇文章主要介绍了ajax中设置contentType: "application/json"的作用,需要的朋友可以参考下 最近在做项目交互的时候,刚开始向后台传递数据返回 415 ...

  9. Ajax(form表单文件上传、请求头之contentType、Ajax传递json数据、Ajax文件上传)

    form表单文件上传 上菜 file_put.html <form action="" method="post" enctype="multi ...

最新文章

  1. 无法使用xcode打出ipa包的解决方法
  2. VSCODE编译头文件时函数没有定义的解决方案(VSCODE手动链接C文件方法)
  3. 逆转衰老!“70岁”小鼠经过数月治疗,肾脏皮肤血液细胞重返“年轻态”
  4. React Native JSBundle拆包之原理篇
  5. Module 'matplotlib' has no 'contourf' member 使用Python导入matplotlib模块报错
  6. 零基础学习java------day7------面向对象
  7. read-only file system怎么改权限_“我就退出家长群!怎么了?”压垮成年人仅需一个“家长群”上热搜?...
  8. 《CLR via C#》 第三版的主要内容
  9. JavaFx loading 数据加载中效果
  10. 字节跳动 数据分析 一轮技术面
  11. Android中的常用控件之进度条(ProgressBar)
  12. 测试公总号加入微信开放平台
  13. 7-2 求素数个数 (30分)
  14. 7-1 软硬车厢交替排列 (13 分)
  15. [Matlab] Galois Field
  16. 再读德鲁克#2 如何提升生产率
  17. ggplot2-条形图和折线图
  18. SMP、COW、PVP、MPP计算机相关
  19. 主线程 子线程死掉_当线程死时,子进程也会死
  20. 让ie6也支持websocket

热门文章

  1. 计算机数据ppt,《计算机数据表示》PPT课件.ppt
  2. 深度学习环境配置TensorFlow2+Keras
  3. scrapy框架爬取建设行业数据实例(思路整理)
  4. Android代码模拟物理、屏幕点击事件 、APP内部自动点击
  5. 伪原创视频怎么做 视频md5修改批量修改器
  6. 【脱壳-寻找OEP】壳常用的函数寻找OEP
  7. 由于目标计算机积极拒绝,无法连接。 (10061)
  8. 高德地图 web api 使用
  9. IOS9以上如何导入铃声并设置
  10. 基于Python实现头像戴上圣诞帽案例