无效的HTTP状态代码405:for $ http.put

时间:2015-09-18 06:25:22

标签: angularjs

我有服务可以使用curl PUT来更改属性的值:

curl -l -X PUT -d processed=1 "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1"

curl -l -X PUT -d processed=0 "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1"

我想在Angularjs中实现它:

        var url = "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=" + id;
        var data = { 'processed': processed } ;
        console.log("debug", url);
        console.log("debug", data);
        $http.put(url, data)
          .success(function (response)
          {
            console.log("debug",response);
          });

但是我遇到了以下错误:

XMLHttpRequest cannot load http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1. Invalid HTTP status code 405

我该怎么办?感谢...

更新

离子服务中存在问题,当我在我的Android设备上调试时,代码工作正常:

                $http({
                    method: 'PUT', // support GET, POST, PUT, DELETE
                    url: "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=" + id,
                    data: 'processed=1',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                    },
                    timeout: 30000, // timeout abort AJAX
                    cache: false
                }).
                success(function(data, status, headers, config) {
                    // this callback will be called asynchronously
                    // when the response is available
                    console.log("success", data);
                }).
                error(function(data, status, headers, config) {
                    // called asynchronously if an error occurs
                    // or server returns response with an error status.
                    console.error("error", data);
                });

1 个答案:

答案 0 :(得分:0)

离子服务中存在问题,当我在我的Android设备中调试时,代码工作正常。