我遇到了一些問題,我試圖對後端php執行http post請求。我是新角色,想要嘗試不同的REST方法。我很擅長GET方法。在此之後,我會嘗試更新和刪除方法,但現在我堅持這一點。 T__T。
在這裏,在PHP
$data = array(
"email" => $email,
"password" => $this->input->post("password")
);
$insert_data = $this->player_registration->insert($data);
在這裏,我廠
angular.module('myApp.services', ['ngResource'])
.factory('webService', function($resource){
var apiUrl = "http:domain.com/feed/"; //change this to web service
var factory = {};
factory.registerPlayer = function() {
return $resource(apiUrl + ':type', {type:'player'}, {
post: {method:'POST', params: {}}
});
};
factory.getPlayerByEmail = function() {
return $resource(apiUrl + ':type', {type:'player'}, {
get: {method: "GET", params: {}}
});
};
return factory;
})
而我控制了一下代碼
function registerController($scope, webService) {
$scope.inputs = {};
$scope.inputs.email = "[email protected]";
$scope.inputs.password = "password";
var req = new webService.registerPlayer($scope.inputs);
req.save()
我app.js
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers'])
爲什麼不直接在服務中使用HTTP POST而不是使用$ resource? – BKM
使用$ http與$ resource相比更好嗎? –
是的,使用$ http而不是$ resource會更好。 – BKM