angular.js - angular怎么发一个带json的get请求
世界只因有你
世界只因有你 2017-05-15 16:50:21
0
5
624

我发现手册上get并没有提供这么个方式?

世界只因有你
世界只因有你

reply all(5)
阿神

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:

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.module('ngApp')
.controller('aboutCtrl', function ($scope, $http) {
var url = 'xxx.json';
$http.get(url).success(function (data) {
$scope.tableDate = data
})
});

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template