get:
$http.get("http://192.168.2.33:8080/v1/member.a?wcid=" + $scope.wcid).success(function(response) {
$scope.member = response.body;
});
post: 这个有两种形式,一种是最熟悉的表单提交,还有一种就是将参数转为data来传参
一:表单提交
<form id="form_add" method="post" enctype="multipart/form-data">
<table>
<tbody>
<tr><td>uid</td><td><textarea id="uid" name="uid" rows="1" cols="80">1</textarea></td></tr>
<tr><td>name</td><td><textarea id="name" name="name" rows="5" cols="80"></textarea></td></tr>
<tr><td>view</td><td><textarea id="view" name="view" rows="1" cols="80">0</textarea></td></tr>
<tr><td>comment</td><td><textarea id="comment" name="comment" rows="1" cols="80">0</textarea></td></tr>
<tr><td>favorite</td><td><textarea id="favorite" name="favorite" rows="1" cols="80">0</textarea></td></tr>
<tr><td>price</td><td><textarea id="price" name="price" rows="1" cols="80">0</textarea></td></tr>
<tr><td>address</td><td><textarea id="address" name="address" rows="5" cols="80"></textarea></td></tr>
<tr><td>brand</td><td><textarea id="brand" name="brand" rows="1" cols="80"></textarea></td></tr>
<tr><td>description</td><td><textarea id="description" name="description" rows="5" cols="80"></textarea></td></tr>
<tr><td>t1</td><td><textarea id="t1" name="t1" rows="1" cols="80">1</textarea>1推荐 2 吐槽</td></tr>
<tr><td>t2</td><td><textarea id="t2" name="t2" rows="1" cols="80">1,2</textarea>1 白领家具 2 办公室小确幸 3 人在旅途 4 生命在于运动</td></tr>
<tr><td>pid</td><td><textarea id="pid" name="pid" rows="1" cols="80">0</textarea></td></tr>
<tr><td><input type="submit" value="add" ng-click="add()" /></td><td>{{json.message}}</td></tr>
</tbody>
</table>
</form>
// js 中:
var app = angular.module('admin', []);
app.controller('post_add', function($scope, $http) {
$scope.add = function() {
var formdata = new FormData($("form_add"));
$http({
method: 'POST',
url: "http://192.168.2.33:8080/v1/admin_post_add.a",
data: formdata,
headers: {
'Content-Type': undefined
},
transformRequest: angular.identity
}).success(function(response) {
$scope.json = response.body;
});
}
});
二:将参数转为data,post请求
var orderAddParamData = {"mid": $scope.member.guid, "count" : $scope.count, "amount": $scope.allMoney, "cids": $scope.cartGuid, "counts": $scope.counts, "amounts": $scope.amounts};
$http({
method: 'POST',
url: "http://192.168.2.33:8080/v1/order_add.a",
data: $.param(orderAddParamData),
headers: {
'Content-Type': "application/x-www-form-urlencoded"
},
transformRequest: angular.identity
}).success(function(response) {
console.log(response.body);
});