【问题标题】:How to post a json to my app ionic => symfony fosrestbundle如何将 json 发布到我的应用程序 ionic => symfony fosrestbundle
【发布时间】:2016-05-21 12:47:21
【问题描述】:

我是 angularJs 的新手,我的 ionic 我尝试发布的应用 我的应用程序 symfony fosrestbundle 的 json 我的应用程序配置正确。

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

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

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

【问题讨论】:

    标签: angularjs ionic-framework fosrestbundle ngresource


    【解决方案1】:

    你做得怎么样?

    首先你需要像这样将函数绑定到你的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
             });
         }
        };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      • 2016-08-01
      • 2021-03-17
      相关资源
      最近更新 更多