我发现手册上get并没有提供这么个方式?
What you mean by bringing JSON is to pass JSON parameters to the backend in RequestBody, right?
If this is the case, then you are thinking wrong. It’s not that Angular doesn’t provide it, but that you shouldn’t do it
If you want to make a get request, you can only spell the address
Can be achieved through $resource,
HTTP GET方法不支持传body域,如果你指的是将JSON通过参数传递的话应该先将JSON进行URLEncode, that is:
HTTP GET
body
JSON
URLEncode
var data = {'foo': 'bar'}; var json_str = JSON.stringify(data); var encoded_param = encodeURIComponent(json_str); // 转码 $http.get('/path', { params: { encoded_param: userencoded_paramid } });
The words passed through Angular $http should be
Angular $http
angular.module('ngApp') .controller('aboutCtrl', function ($scope, $http) { var url = 'xxx.json'; $http.get(url).success(function (data) { $scope.tableDate = data }) });
What you mean by bringing JSON is to pass JSON parameters to the backend in RequestBody, right?
If this is the case, then you are thinking wrong. It’s not that Angular doesn’t provide it, but that you shouldn’t do it
If you want to make a get request, you can only spell the address
Can be achieved through $resource,
HTTP GET
方法不支持传body
域,如果你指的是将JSON
通过参数传递的话应该先将JSON
进行URLEncode
, that is:The words passed through
Angular $http
should beangular.module('ngApp')
.controller('aboutCtrl', function ($scope, $http) {
var url = 'xxx.json';
$http.get(url).success(function (data) {
$scope.tableDate = data
})
});