javascript - $ http获取参数确实n

有谁知道为什么这不起作用?

$http
    .get('accept.php', {
        source: link,
        category_id: category
    })
    .success(function (data, status) {
        $scope.info_show = data
    });

这确实有效:

$http
    .get('accept.php?source=' + link + '&category_id=' + category)
    .success(function (data, status) {
        $scope.info_show = data
    });
kahonmlg asked 2019-08-13T23:34:30Z
2个解决方案
191 votes

get调用中的第二个参数是配置对象。 你想要这样的东西:

$http
    .get('accept.php', {
        params: {
            source: link,
            category_id: category
        }
     })
     .success(function (data,status) {
          $scope.info_show = data
     });

有关更多详细信息,请参见[http://docs.angularjs.org/api/ng.$http]的参数部分

dnc253 answered 2019-08-13T23:34:51Z
3 votes

.success docs,第二个参数是配置对象:

.success

执行.success请求的快捷方法。

您可以将代码更改为:

$http.get('accept.php', {
    params: {
        source: link, 
        category_id: category
    }
});

要么:

$http({
    url: 'accept.php', 
    method: 'GET',
    params: { 
        source: link, 
        category_id: category
    }
});

请注意,由于不再使用Angular 1.6:.success,请使用.then

$http.get('/url', config).then(successCallback, errorCallback);
Mistalis answered 2019-08-13T23:35:45Z
translate from https://stackoverflow.com:/questions/17225088/http-get-parameters-does-not-work