简体   繁体   中英

Failed to load resource: the server responded with a status of 405 (Method Not Allowed) api

When I run http-server -o with angularjs(frontend) to use api from symfony (backend) for login, I get this error:

Failed to load resource: the server responded with a status of 405 (Method Not Allowed) :8080/app/api/src/AppBundle/Controller/MainController.php

error Impossible d'accéder au serveur.

connection.js

'use strict';
    angular.module('myapplication.connection', ['ngRoute'])
    .config(['$routeProvider', function($routeProvider) {
      $routeProvider.when('/connection', {
        templateUrl: 'connection/connection.html',
        controller: 'connectionCtrl'
      });}])
    .controller('connectionCtrl', ['$http', '$scope', function($http, $scope) {
        $http.post('api/src/AppBundle/Controller/MainController.php', {formType:'connection'})
    .then(function (response) {
            $scope.connection = response.data;
        }, function(response) {
            $scope.connection = "Impossible d'accéder au serveur.";
        }); 
    }]);

connection.html(form)

<div class="content">
    <h2>Connexion</h2>
    <div>{{ connection }}</div>
</div>

How do I solve this error?

The backend likely requires you to set Content-Type and/or Accept in your request header. See here for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM