Ajax POST单个对象或多个对象至API
如下图示例:
前端在引用这个2个Action时,POST单个对象,或多个对象作为参数传至服务端的API。
传单外对象:
var _obj = {}; _obj.Item_Code = code; $http({ method: 'POST', url: '/Item/Delete/', dataType: 'json', headers: { 'Content-Type': 'application/json; charset=utf-8' }, data: JSON.stringify(_obj), })
传多个对象:
var objects = new Array(); var obj = null; angular.forEach($scope.Items, function (item) { obj = new Object(); if (item.checkSingle) { obj.Item_Code = item.Item_Code; objects.push(obj); } }); $http({ method: 'POST', url: '/Item/BulkDelete', dataType: 'json', headers: { 'Content-Type': 'application/json; charset=utf-8' }, data: JSON.stringify(objects), })