简体   繁体   中英

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

my config:

.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/ajax/create', {
        templateUrl: 'view/pagination/pagination.html',
        controller: 'AjaxCtrl'
    });

    $routeProvider.when('/ajax/update/:id', {
        templateUrl: 'view/pagination/pagination.html',
        controller: 'AjaxCtrl'
    });

    $routeProvider.when('/ajax/delete/:id', {
        templateUrl: 'view/pagination/pagination.html',
        controller: 'AjaxCtrl'
    });

}])

my code process:

        $scope.doEdit = function(item) {
            var notice = "Item #" + item.id + " has been edited with amount: " + item.amount;

            $http.put('/ajax/update/' + item.id).then(function(data) {
                alert(notice);
            });
        }

I'm trying all method put, delete
all of them have error without method get althought it still working

error in console

在此处输入图片说明

a 405 Method Not Allowed indicates that the user agent (the web browser, in most cases) has requested a valid resource using an invalid HTTP method. This could happen in a few different circumstances:

  • The user agent is accidentally sending an incorrect HTTP method.
  • The server is expecting only a handful of valid HTTP methods for the requested resource.

So look into your server which HTTP method the API supports.

add this nginx.conf

    add_header Allow "GET, POST, HEAD, PUT" always;

    if ( $request_method !~ ^(GET|POST|HEAD|PUT)$ ) {
        return 405;
    }

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