简体   繁体   English

AngularJS无法加载资源:服务器响应状态为403()

[英]AngularJS Failed to load resource: the server responded with a status of 403 ()

Frontend code 前端代码

      var app = angular.module('myApp', ['ngResource']);
         app.controller('UserController', ['$scope', '$resource',function($scope,$resource) 
            {
         $scope.deleteRec = function(username)
                 {
                    User = $resource(
                            'delete/:username',
                            {},
                             {method:'DELETE', params: {username: '@username'}});
                    User.delete({username: $scope.myform.username}).$promise.then(function successCallback(response) 
                    {
                        $scope.Message = response;
                    }, function errorCallback(response) {

                    });

                    $scope.myform.username = "";
                    $scope.myform.phone="";
                    $scope.myform.email="";
                  };

         }]);
<table border="1" width="50%" height="50%"> 
    <tr><th>user_name</th><th>phone</th><th>email</th><th>delete</th></tr>
     <tr data-ng-repeat="user in usernames">
     <td><span data-ng-bind="user.username"></span></td>
      <td><span data-ng-bind="user.phone"></span></td>
       <td><span data-ng-bind="user.email"></span></td>
        <td><button data-ng-click="deleteRec(user.username)">delete</button>
       </tr>   
   </table>   

Spring Controller code 弹簧控制器代码

@RequestMapping(value="/delete/{username}")
    @ResponseBody
    public String delete(@PathVariable String username) 
    {
        String user=retrievedataservice.delete(username);
        return user;
    }

how to delete the particular record through angularjs request. 如何通过angularjs请求删除特定记录。 Angularjs does not send the parameter to spring controller AngularJS不会将参数发送到Spring控制器

in angularjs, do the API call for once as: 在angularjs中,一次执行API调用:

$http({
  method: 'DELETE',
  url: 'delete/:username,
  data: {
    username: $scope.myform.username
  },
  headers: {
    'Content-type': 'application/json;charset=utf-8'
  }
}).then(function(response) {
    $scope.Message = response

}); });

in spring: 在春天:

public String delete(@PathVariable('username') String username){}

@PathVariable is used for accessing parameters from URI template @PathVariable用于从URI模板访问参数

or instead use, 或者使用

public String delete(@RequestParam String username){}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载资源:服务器响应状态为 403(禁止访问)MVC 5 - Failed to load resource: the server responded with a status of 403 (Forbidden) MVC 5 加载资源失败:服务器响应状态为 405(方法不允许)angularjs - Failed to load resource: the server responded with a status of 405 (Method Not Allowed) angularjs 无法加载资源:服务器响应状态为404 angularjs - Failed to load resource: the server responded with a status of 404 angularjs AngularJS-$ http加载资源失败:服务器响应状态为404 - AngularJS - $http Failed to load resource: the server responded with a status of 404 Angular.js库无法加载资源:服务器响应状态为404(未找到) - Angularjs libs Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为415 - Failed to load resource: the server responded with a status of 415 Google-map API给出无法加载资源:服务器的响应状态为403() - Google-map API giving Failed to load resource: the server responded with a status of 403 () 加载资源失败:服务器响应状态为500(内部服务器错误)-Angularjs和Codeigniter - Failed to load resource: the server responded with a status of 500 (Internal Server Error) - Angularjs and Codeigniter 上载图像AngularJS未能加载资源:服务器的响应状态为405(不允许使用方法) - Uploading an image, AngularJS, Failed to load resource: the server responded with a status of 405 (Method Not Allowed) 无法加载资源:服务器响应从Angularjs到WebApi的状态为405(方法不允许) - Failed to load resource: the server responded with a status of 405 (Method Not Allowed) from Angularjs to WebApi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM