序列化form表单内容为json对象

SourceCode:

 1 ; (function ($) {
 2     $.fn.extend({
 3         serializeJson: function () {
 4             var json = {};
 5             $(this.serializeArray()).each(function () {
 6                 if (json.hasOwnProperty(this.name)) {
 7                     if (Array.isArray(json[this.name])) {
 8                         json[this.name].push(this.value);
 9                     } else {
10                         var list = [json[this.name], this.value];
11                         json[this.name] = list;
12                     }
13                 } else {
14                     json[this.name] = this.value;
15                 }
16             });
17             return json;
18         }
19     });
20 })(jQuery); 

 

前台请求code:


 

后台ASP.MVC接收:


 

FireBug-Console:

posted @ 2016-03-24 16:10  youtao  阅读(702)  评论(0编辑  收藏  举报