send js object to webapi or mvc
[HttpPost]
public HttpResponseMessage AddInfo(UserInfoEntity userInfo)
{
return Request.CreateResponse(HttpStatusCode.OK,
string.Format("{0},{1},{2}", userInfo.UserName, userInfo.Name, userInfo.PassWord));
}
<script type="text/javascript">
(function () {
var createXhr = function () {
var xhr;
if (window.ActiveXObject) {
xhr = new XMLHttpRequest();
} else {
xhr = new XMLHttpRequest();
}
return xhr;
};
var ajax = function (obj) {
var xhr = createXhr();
xhr.open(obj.type, obj.url, true);
debugger;
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(obj.data);
xhr.onreadystatechange = function () {
//请求成功
if (xhr.readyState == 4 && xhr.status == 200) {
obj.success(xhr.responseText);
}
obj.complete();
};
};
window.common = {
ajax: ajax
};
})(); $("#btnOk").on("click", function () {
common.ajax({
url: "/Default/AddInfo",
type: "post",
dataType: "json",
data: JSON.stringify({
Name: "张三",
UserName: "zhangsan",
PassWord: "123456"
}),
success: function (result) {
alert(result);
},
complete: function () {
}
});
});
</script>
这种方式webapicontroller和mvccontroller都可以接收到,不用反序列化,亲测可以
send js object to webapi or mvc的更多相关文章
- js基础 js自执行函数、调用递归函数、圆括号运算符、函数声明的提升 js 布尔值 ASP.NET MVC中设置跨域
js基础 目录 javascript基础 ESMAScript数据类型 DOM JS常用方法 回到顶部 javascript基础 常说的js包括三个部分:dom(文档document).bom(浏览器 ...
- JS Object.defineProperties()方法
JS Object.defineProperties()方法 描述: Object.defineProperties()方法为目标对象同时配置多个属性. 语法: Object.defineProper ...
- js & Object reference bug
js & Object reference bug bug object ref bug onClickButton (type = ``) { let { publishDate: publ ...
- JS Object Deep Copy & 深拷贝
JS Object Deep Copy & 深拷贝 针对深度拷贝,需要使用其他方法 JSON.parse(JSON.stringify(obj));,因为 Object.assign() 拷贝 ...
- JS Object Deep Copy & 深拷贝 & 浅拷贝
JS Object Deep Copy & 深拷贝 & 浅拷贝 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Refe ...
- js & object & prototype & __proto__ & prototype chain
js & object & prototype & proto & prototype chain constructor prototype === instance ...
- js架构设计模式——你对MVC、MVP、MVVM 三种组合模式分别有什么样的理解?
你对MVC.MVP.MVVM 三种组合模式分别有什么样的理解? MVC(Model-View-Controller)MVP(Model-View-Presenter)MVVM(Model-View-V ...
- Autofac 及 Autofac.WebApi 与MVC版本兼容问题
环境:vs2013 下载 Autofac 时,会自动把 Microsoft.AspNet.Mvc 更新到 5.2.3.原来是 5.0.0.0 再使用 Autofac.WebApi , 出现以下问题: ...
- JS - Object and Property的删除用法
在JS中,Object和Property的删除用法: var myObject = {name:'jimmy', age:12, height:123} delete myObject["j ...
随机推荐
- 国内常用ntp服务器ip地址
ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)s1a.time.edu.cn 北京邮电大学s1b.time.edu.cn 清华大学s1c.time ...
- 【IPC通信】基于管道的popen和pclose函数
http://my.oschina.net/renhc/blog/35116 [IPC通信]基于管道的popen和pclose函数 恋恋美食 恋恋美食 发布时间: 2011/11/12 23:20 ...
- Unity 之 Redux 模式(第二篇)—— Rigidbody 改造,摄像机控制
作者:软件猫 日期:2016年12月8日 转载请注明出处:http://www.cnblogs.com/softcat/p/6144041.html 上一篇文章中存在一个很严重的问题,首先我们先让 M ...
- CentOS 6.8yum源的配置
Centos配置163的yum源 1.首先备份当前系统的yum源 # mv /etc/yum.repo.d/Centos-Base.repo /etc/yum.repo.d/Centos-Base.r ...
- oracle修改闪回日志的位置
改变闪回日志位置的步骤: A.Change the value of the DB_RECOVERY_FILE_DEST initialization parameter to a new value ...
- Arcgis Runtime sdk for android 授权
要下载和安装 ArcGISRuntime SDK for Android,您需要注册开发者账户,进而便拥有了访问所有功能的权限,从而实现开发和测试目的.但是,这种情况下,应用程序中的所有地图都具有水印 ...
- Android学习之菜单
android中包含多种菜单,本例带来的是选项菜单和上下文菜单. 1.选项菜单 在android中,开发者可以在xml文档中部署所要添加的菜单,在后台调用即可. <menu xmlns:andr ...
- 2015.01.06 JQuery
jQuery是一个兼容多浏览器的javascript库.开发出来的JavaScript的脚本包.非侵入性的脚本. 下载地址:http://jquery.com/ (打不开网页需要翻* ...
- node学习第一篇
创建一个http服务器 //app.js var http = require("http"); function start(req, res){ //res.writeHead ...
- node.js安装以及相关配置
安装: 首先需要进行安装.关于如何安装Node.js,这里就不赘述了,可以直接参考官方的安装指南.安装到指定盘后(以下内容以D盘为例),就开始进行相关配置. 配置: 首先配置环境变量:我的电脑--&g ...