有谁知道为什么这不起作用?
$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
});
答案 0 :(得分:191)
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的参数部分了解更多详情
答案 1 :(得分:3)
从$http.get
docs开始,第二个参数是配置对象:
get(url, [config]);
执行
GET
请求的快捷方式。
您可以将代码更改为:
$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
should not be used anymore,请改用.then
:
$http.get('/url', config).then(successCallback, errorCallback);