简体   繁体   English

错误 405(方法不允许)

[英]Error 405 (Method not allowed)

I'm trying to post a form using angularJs with the $http.post method.我正在尝试使用带有 $http.post 方法的 angularJs 发布表单。 But whenever i execute this function it gives me this error: Failed to load resource: the server responded with a status of 405 (Method Not Allowed) I have no clue what to do.但是每当我执行这个函数时,它都会给我这个错误:加载资源失败:服务器响应状态为 405(方法不允许)我不知道该怎么做。 (Im using visual studio 2015) (我使用的是 Visual Studio 2015)

 $scope.addRow = function () {
        var parameter = JSON.stringify({ id: 99, first_name: $scope.firstName, last_name: $scope.lastName, email: $scope.email, country: $scope.country, phone_number: $scope.phoneNumber });
        $http.post('MOCK_DATA.json', parameter).success(function (data, status, headers, config) {
            console.log(data);
        })

You have a file : 'MOCK_DATA.json' .你有一个文件: 'MOCK_DATA.json' The only thing you are allowed to do with this file is retrieving it from your client.您可以对这个文件做的唯一一件事就是从您的客户端检索它。 (Http Verb 'GET'). (Http动词'GET')。

If you want to update this file to add values, you must create a controller that will receive your object.如果要更新此文件以添加值,则必须创建一个将接收对象的控制器。 Inside this controller you will have to write new lines into your file.在此控制器中,您必须在文件中写入新行。

I think I 've often had this problem because the parameters of the query that does not pass.我想我经常遇到这个问题,因为查询的参数没有通过。 Try something like this:尝试这样的事情:

$http({
     url: '/api/customers/GetFilteredList',
     params: { 
        'lastName': lastName,
        'firstName': firstName,
        'address': address,
        'town': town,
        'zipCode': zipCode,
        'skip': skip,
        'take': take 
     } 
 });

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

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