我正在使用这个教程:http://rabidgadfly.com/2013/02/angular-and-xml-no-problem/
为了启动XML应用程序,当我设置外部xml (Feedburner)告诉我没有访问权限时,有人知道它会是什么吗?
HTML:
<section ng-controller="AppController" class="container-podcastapp">
<ul>
<li ng-repeat="guitar in dataSet">
<div class="resultwrapper">
<h2>{{item.title}}</h2>
</div>
</li>
</ul>
</section>javascript:
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);
};发布于 2013-08-06 04:46:17
"Method 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);
});
}
};
}]);https://stackoverflow.com/questions/18064106
复制相似问题