search

Home  >  Q&A  >  body text

angular.js - angular怎么发一个带json的get请求

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

世界只因有你世界只因有你2743 days ago626

reply all(5)I'll reply

  • 阿神

    阿神2017-05-15 16:52:21

    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

    reply
    0
  • 为情所困

    为情所困2017-05-15 16:52:21

    If you want to make a get request, you can only spell the address

    reply
    0
  • 为情所困

    为情所困2017-05-15 16:52:21

    Can be achieved through $resource,

    reply
    0
  • 怪我咯

    怪我咯2017-05-15 16:52:21

    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

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:52:21

    angular.module('ngApp')
    .controller('aboutCtrl', function ($scope, $http) {
    var url = 'xxx.json';
    $http.get(url).success(function (data) {
    $scope.tableDate = data
    })
    });

    reply
    0
  • Cancelreply