Javascript (不允许使用方法)json的外部xml

Javascript (不允许使用方法)json的外部xml,javascript,xml,json,angularjs,Javascript,Xml,Json,Angularjs,我正在使用本教程: 要启动XML应用程序, 当我设置外部xml Feedburner时,它告诉我我没有访问权限,有人知道它可能是什么吗 HTML: 方法not allowed通常意味着将请求发送到的服务配置为禁止特定请求类型POST、GET和OPTIONS 既然您正在尽我所能尝试使用GET方法,我建议您尝试使用POST 另一方面,在某些情况下,服务器会同时禁止跨域ajax请求——很可能您查询的URL实际上不是服务器上的静态文件,而是某种服务,在这种情况下,必须将其配置为允许来自不同域的ajax

我正在使用本教程:

要启动XML应用程序, 当我设置外部xml Feedburner时,它告诉我我没有访问权限,有人知道它可能是什么吗

HTML:


方法not allowed通常意味着将请求发送到的服务配置为禁止特定请求类型POST、GET和OPTIONS

既然您正在尽我所能尝试使用GET方法,我建议您尝试使用POST

另一方面,在某些情况下,服务器会同时禁止跨域ajax请求——很可能您查询的URL实际上不是服务器上的静态文件,而是某种服务,在这种情况下,必须将其配置为允许来自不同域的ajax请求

如果您可以使用Fiddler或其他有帮助的工具发布整个错误/响应,以防使用post无法完成任务

编辑:

尝试对您的服务进行以下更改:

angular.module('myApp.service',[]).
factory('DataSource', ['$http',function($http){
   return {
       get: function(file,callback,transform){
            $http.post(file, {}, {transformResponse:transform}). // this is the change
            success(function(data, status) {
                console.log("Request succeeded");
                callback(data);
            }).
            error(function(data, status) {
                console.log("Request failed " + status);
            });
       }
   };
}]);

谢谢你的回复。如果您在上面的示例中看到它,唯一改变的是本地文件url:var source_file=guitars.xml,改为:var source_file=podcasting/ac360/rss.xml;还更改了返回:return json.channel.item;谢谢。这很有意义——当访问本地XML文件时,您实际上是在向某个静态本地资源发出GET请求,这是可行的。当切换到所述URL时,您正在向可能由某个底层服务动态创建的资源发出GET请求,如果该服务被配置为只接受POST请求(这种情况非常常见),那么您将获得“方法不允许”错误。您是否尝试使用$http.post?只是别忘了post需要3个参数:url,本例中的数据是一个空白的{}&config.put你放在我这里的修改过的代码仍然会生成这个错误:谢谢从我看到的,你现在得到一个404错误。。。与此问题无关,它只是意味着xml文件不存在。我尝试访问您之前提到的@cnn.com的URL,它会一起阻止跨域请求。因此,只需找到一些您知道可以肯定访问的静态xml文件,然后使用get/post处理这些文件,具体取决于服务器。
angular.module('myApp.service',[]).
    factory('DataSource', ['$http',function($http){
       return {
           get: function(file,callback,transform){
                $http.get(
                    file,
                    {transformResponse:transform}
                ).
                success(function(data, status) {
                    console.log("Request succeeded");
                    callback(data);
                }).
                error(function(data, status) {
                    console.log("Request failed " + status);
                });
           }
       };
    }]);

angular.module('myApp',['myApp.service']);

var AppController = function($scope,DataSource) {

    var SOURCE_FILE = "http://rss.cnn.com/services/podcasting/ac360/rss.xml";

    xmlTransform = function(data) {
        console.log("transform data");
        var x2js = new X2JS();
        var json = x2js.xml_str2json( data );
        return json.item;
    };

    setData = function(data) {
        $scope.dataSet = data;
    };

    DataSource.get(SOURCE_FILE,setData,xmlTransform);

};
angular.module('myApp.service',[]).
factory('DataSource', ['$http',function($http){
   return {
       get: function(file,callback,transform){
            $http.post(file, {}, {transformResponse:transform}). // this is the change
            success(function(data, status) {
                console.log("Request succeeded");
                callback(data);
            }).
            error(function(data, status) {
                console.log("Request failed " + status);
            });
       }
   };
}]);