【发布时间】:2015-10-31 09:45:42
【问题描述】:
我将从 url 获得的 id 发送到服务器(php 页面)。
我从 url 获取并通过 angularjs 中的post 方法发送的方式:
(注意: 我检索数据并在 console.log() 中打印正常,问题是我想将它们放入 $scope 的位置)
.controller('PlaylistCtrl', function($scope, $stateParams, $http) {
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http({
method: 'POST',
url: 'http://cms.focusweb.ir/Json/get_article',
data: { id: $stateParams.playlistId },
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(response) {
// This works right
console.log(response);
// PROBLEM IS HERE
angular.forEach(response, function(response){
$scope.articles_content.push(response);
});
})
.error(function(data, status, headers, config) {
// handle error things
});
});
我的 PHP 代码是:
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$article_ID = $request->id;
我得到的错误是:
【问题讨论】:
标签: angularjs angularjs-scope angularjs-service angularjs-http