【问题标题】:Angularjs http.delete is not working after deploying project on server在服务器上部署项目后,Angularjs http.delete 不起作用
【发布时间】:2016-06-02 04:40:39
【问题描述】:

我正在做一个 Laravel5.1 项目。在使用 xampp http.delete 在本地主机上工作时工作正常,但在远程服务器上托管项目后,虽然其他属性工作正常,但此删除选项不起作用。 这是部分代码

$scope.removeSaleTemp = function(id) {
        $http.delete('api/saletemp/' + id).
        success(function(data, status, headers, config) {
            $http.get('api/saletemp').success(function(data) {
                    $scope.saletemp = data;
                    });
            });
    }

'api/saletemp/' 转到 SaleTempApiController

public function destroy($id)
{
    SaleTemp::destroy($id);
}

查看部分:

<tr ng-repeat="newsaletemp in saletemp">
                                <td>@{{newsaletemp.item_id}}</td><td>@{{newsaletemp.item.item_name}}</td><td>@{{newsaletemp.item.selling_price | currency}}</td><td><input type="text" style="text-align:center" autocomplete="off" name="quantity" ng-change="updateSaleTemp(newsaletemp)" ng-model="newsaletemp.quantity" size="2"></td><td>@{{newsaletemp.item.selling_price * newsaletemp.quantity | currency}}</td><td><button class="btn btn-danger btn-xs" type="button" ng-click="removeSaleTemp(newsaletemp.id)"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></td>
 </tr>

请注意,此代码在 localhost (xampp) 上运行良好,但在服务器中部署后失败。

【问题讨论】:

  • 你用的是windows系统吗?
  • 出于开发目的,是的。
  • 很可能是区分大小写的问题。确保您在角度部分和 php 部分使用相同的案例。 SaleTempsaletemp在unix系统中是不同的。
  • 只是按照您所说的将 SaleTemp 重构为 satetemp 但没有奏效。如果级联是一个问题,那么为什么其他功能可以正常工作?
  • 服务器的http响应是什么?可能是 CORS 问题

标签: php angularjs laravel-5.1


【解决方案1】:

可能是您调用了错误的网址。我认为您正在尝试致电 www.example.com/api/saletemp/1。相反,您正在调用 www.example.com/something/api/saletemp/1 网址。为确保您使用的网址正确,请输入$http.delete('/api/saletemp/' + id)

也许这会有所帮助。

【讨论】:

  • HasiburRahmanOmi vai,如果是调用 url 的问题,那么为什么它可以在 localhost 上工作?
  • 本地主机和远程服务器以不同的方式工作。比如:当你调用 localhost/project 时,它会调用你的项目。但是如果你调用 www.example.com/project 那么它会尝试找到页面
【解决方案2】:

Google 了很多,找到了解决方案。 只有我需要在根目录的.htaccess 文件中添加以下权限

<Limit GET POST PUT DELETE HEAD OPTIONS>
    Order allow,deny
    Allow from all
</Limit>
<LimitExcept GET POST PUT DELETE HEAD OPTIONS>
   Order deny,allow
   Deny from all
</LimitExcept>

【讨论】:

    猜你喜欢
    • 2022-01-13
    • 2022-06-29
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-04-28
    相关资源
    最近更新 更多