ajax contentType
//写在前面的话//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相关推荐
- $.ajax() contenttype,$.ajax 中的contentType类型
前言 今天在搞项目的时候遇到一个问题,$.ajax 设置数据类型 applicaiton/json以后,服务器端(express)就拿不到数据,遂解决后将问题以及问题缘由整理下来.jquery 正文 ...
- jQuery ajax contentType processData 笔记
contentType contentType 默认:'application / x-www-form-urlencoded; charset = UTF-8' 类型:Boolean或者String ...
- contenttype文件ajax_jquery ajax contentType设置
默认get方法没有contentType,post方法的contentType为:application/x-www-form-urlencoded; charset=UTF-8 (1) 设置成app ...
- ajax contentType 设置
$.ajax({type: "POST", // 提交方式 get/posturl: url,contentType: "application/json", ...
- 关于 ajax Content-Type 的问题 贼拉有用的!!!
之前我写ajax根本就没有去关注响应头什么的 只是很简单的用而已 后来发现其实没那么简单 Content-Type 指的是发送至服务器的数据类型,而data-Type定义的是服务器返回的数据类型.此处 ...
- Ajax如何设置contenttype,jquery ajax contentType设置
默认get方法没有contentType,post方法的contentType为:application/x-www-form-urlencoded; charset=UTF-8 (1) 设置成app ...
- ajax contenttype详解_jQuery ajax contentType processData 笔记
contentType contentType 默认:'application / x-www-form-urlencoded; charset = UTF-8' 类型:Boolean或者String ...
- js ajax contenttype,ajax中设置contentType: application/json的作用(图文教程)
这篇文章主要介绍了ajax中设置contentType: "application/json"的作用,需要的朋友可以参考下 最近在做项目交互的时候,刚开始向后台传递数据返回 415 ...
- Ajax(form表单文件上传、请求头之contentType、Ajax传递json数据、Ajax文件上传)
form表单文件上传 上菜 file_put.html <form action="" method="post" enctype="multi ...
最新文章
- 无法使用xcode打出ipa包的解决方法
- VSCODE编译头文件时函数没有定义的解决方案(VSCODE手动链接C文件方法)
- 逆转衰老!“70岁”小鼠经过数月治疗,肾脏皮肤血液细胞重返“年轻态”
- React Native JSBundle拆包之原理篇
- Module 'matplotlib' has no 'contourf' member 使用Python导入matplotlib模块报错
- 零基础学习java------day7------面向对象
- read-only file system怎么改权限_“我就退出家长群!怎么了?”压垮成年人仅需一个“家长群”上热搜?...
- 《CLR via C#》 第三版的主要内容
- JavaFx loading 数据加载中效果
- 字节跳动 数据分析 一轮技术面
- Android中的常用控件之进度条(ProgressBar)
- 测试公总号加入微信开放平台
- 7-2 求素数个数 (30分)
- 7-1 软硬车厢交替排列 (13 分)
- [Matlab] Galois Field
- 再读德鲁克#2 如何提升生产率
- ggplot2-条形图和折线图
- SMP、COW、PVP、MPP计算机相关
- 主线程 子线程死掉_当线程死时,子进程也会死
- 让ie6也支持websocket