我有以下 Controller 。它工作得很好(它解析数据并将它们发送到 View 中)。我遇到的唯一问题是它不发送 $http 请求。这是 Controller 的代码块(我只是发送一个测试 $http ,没有从 View 中获取任何值,只是为了测试它是否有效,这不起作用): (还值得一提的是,我通过浏览器的控制台检查是否发送了任何ajax请求)
// Controller
LoginApp.controller("RegisterController", function($scope, $http, registerService){
var username = null;
var password = null;
$scope.registerSubmit = function(){
username = $scope.register.username;
password = $scope.register.password;
};
//registerService.CheckUser();
$http.post('server.php', {name : 'something'})
.success(function(data, status, header, config){
return data;
})
.error(function(data, status, header, config){
return data;
}); // end of $http request
});
编辑:我已经编辑了 @JoshBeam 推荐的内容,将数据传递给 post(),但它没有改变任何内容。
最佳答案
您需要随 HTTP 请求一起传递数据。根据AngularJS documentation ,格式如下: post(url, data, [config]);
因此:
$http.post('server.php', /* your data */);
关于javascript - Controller 中的 Angular $http 请求不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23836428/