码迷,mamicode.com
首页 > 编程语言 > 详细

使用JS传递数组型数据回服务器

时间:2015-03-11 12:05:42      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

//为数组添加一个方法,判断某个值是否存在于数组中
Array.prototype.in_array = function (e) {
for (i = 0; i < this.length && this[i] != e; i++);
return !(i == this.length);
}

 

var array = new Array();

//数组中的Item
var arr = {
//"RFQID": $("#ID").val(),
"RFQID": $(this).attr("rfqid"),
"SiteCode": $(this).attr("site"),
"ProcessID": $(this).attr("processid"),
"ForecastLoading": $(this).val(),
"SimulateNumber": 2,
"MainRFQID": $("#ID").val()
}

array .push(arr); //将Item塞入数组

 

$.ajax({
                    type: "Post",
                    processData: false,
                    contentType: ‘application/json; charset=UTF-8‘,
                    url: "/ReportSimulation/UpdateProcessForecastLoading",
                    data: { list: arrObj },
                    beforeSend: function (xhr, setting) {
                        setting.data = JSON.stringify(setting.data);//转为Json
                    },
                    success: function (r) {
                        if (r.Success) {
                            alert("Success");
                        } else {
                            alert("Error");
                        }
                    }
                });

 

服务器接收:

public ActionResult UpdateProcessForecastLoading(List<ForecastProcessLoadingVM> list)

 

ForecastProcessLoadingVM 申明:

 public class ForecastProcessLoadingVM
    {
        public Guid RFQID { get; set; }
        public string SiteCode { get; set; }
        public Guid ProcessID { get; set; }
        public string ProcessName { get; set; }
        public double? ForecastLoading { get; set; }
        public int SimulateNumber { get; set; }
        public Guid MainRFQID { get; set; }
   }

 

JQGrid中,直接将grid getRowData就可以传回了:

      var gridData = $gridCAPEX.getRowData();
            //var postData = JSON.stringify(gridData);
            //alert("JSON serialized jqGrid data:\n" + postData);

            var data = {
                ID: $("#ID").val(),
                NeedNewCAPEX: $("#NeedNewCAPEX").val(),
                CAPEXVMList: gridData
            };


            $.ajax({
                type: "Post",
                processData: false,
                contentType: ‘application/json; charset=UTF-8‘,
                url: "/BDFormPage/SaveCAPEX",
                data: data,
                beforeSend: function (xhr, setting) {
                    setting.data = JSON.stringify(setting.data);
                },
                success: function (r) {
                    if (r.Success) {
                        alert("Success");
                    } else {
                        alert("Error");
                    }
                }
            });

 

使用JS传递数组型数据回服务器

标签:

原文地址:http://www.cnblogs.com/ceci/p/4329268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!