如何将 json 发布到我的应用程序 ionic => symfony fosrestbundle



我在 angularJs 中很新,在我的离子中我尝试发布的应用一个 JSON 到我的应用程序 Symfony Fosrestbundle 我的应用程序配置正确。

但是当我向控制台发送帖子时显示此错误消息:

XMLHttpRequest 无法加载http://127.0.01/gl/web/api/articles/5/comments .预检响应具有无效状态 405

我快疯了! 有没有人有想法?!非常感谢您的关注

你是怎么做到的?

首先,您需要像这样将函数绑定到您的 html:

<button class="button button-energized" ng-click="login()">Login</button>

建议使用服务进行 http 调用,但您需要在控制器中注入它(LoginService):

.controller('LoginCtrl', function($scope, LoginService) {
 $scope.login = function() {
  LoginService.loginUser($scope.data.user, $scope.data.password)
     .then(function (data) {
      //grant access to the app
     });
 };
});

在您的服务中:

.factory('LoginService', function($http) {
    return {
     loginUser: function(user, password) {
         return $http.post('http://mydomain/login', {
               user: user,
               password: password
         });
     }
    };

最新更新