从AngularJS到Symfony

时间:2016-05-02 08:14:27

标签: php angularjs post symfony

有人可以帮我解决从角度到symfony的POST方法吗? 我使用symfony作为后端,并尝试使用ngResource从angular添加新用户。

我的工厂:

app.factory('sveKlupeServiceFactory', ['$resource',
 function($resource){
var data = $resource('xxxxxx', {klupa: '@klupa'},{
 query: { method: 'GET', isArray:false},
 save : {
        method : 'POST',
        url : "//api-dev.steora.com/control-board/smartbenches",
        headers: {
            'Content-Type': 'application/x-ww-form-urlencoded'
        },            
    }
 });
 return data;

}]);

我的控制器:

  .controller('klupeController', ['$scope', 'sveKlupeServiceFactory', function ($scope,sveKlupeServiceFactory){
sveKlupeServiceFactory.query(function(res){
$scope.klupe = res.smart_benches;
});
$scope.setDataForKlupa = function(klupaID){
    $scope.currentKlupa = sveKlupeServiceFactory.get({klupa: klupaID});
};

$scope.addKlupa = function(){ sveKlupeServiceFactory.save($scope.addKlupa););};

在Chrome控制台和firebug控制台中,我得到了

No 'Access-Control-Allow-Origin' header is present on the requested       resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 400.

后端在标题中添加此内容

Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *

GET工作无法上班。

提前致谢

0 个答案:

没有答案