Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将Wordpress博客文章拉入JS_Javascript_Apache_Angularjs - Fatal编程技术网

Javascript 将Wordpress博客文章拉入JS

Javascript 将Wordpress博客文章拉入JS,javascript,apache,angularjs,Javascript,Apache,Angularjs,我想从类似的东西中提取blog提要,用于不在同一域中的Angular应用程序 我打算使用ProxyPass,但ProxyPass不能与/?feed=rss2一起使用。有没有重写规则可以用来避免Javascript在获取不在同一URL中的内容时出现的跨域问题 我使用AngularJS的服务获取提要内容,就像其他服务一样 下面是我用来获取博客rss的代码: $scope.getBlogPost = function() { $http({method:'GET', url:'http://b

我想从类似的东西中提取blog提要,用于不在同一域中的Angular应用程序

我打算使用ProxyPass,但ProxyPass不能与/?feed=rss2一起使用。有没有重写规则可以用来避免Javascript在获取不在同一URL中的内容时出现的跨域问题

我使用AngularJS的服务获取提要内容,就像其他服务一样

下面是我用来获取博客rss的代码:

$scope.getBlogPost = function() {
    $http({method:'GET', url:'http://blog.neosavvy.com/?feed=rss2'}).
        success(function (data, status, headers, config) {
            console.log("data returned");
        }).
        error(function (data, status, headers, config) {
            console.log("data not returned");
        });
}
这是我收到的错误-因此需要proxypass或其他方法


无法加载XMLHttpRequest。访问控制不允许源站允许源站。

所述URL是RSS源。不需要考虑跨站点脚本编写。RSS是一种可从任何地方提取的XML格式


几乎任何JavaScript框架都能满足您的要求

您可以使用类似或

我用后者做了一个例子,您可以在这里查看:

与使用
$http
服务不同,您将使用googlefeedapi,您的控制器将如下所示

app.controller('ctrl', function($scope) {
  var feed = new google.feeds.Feed("http://blog.neosavvy.com/?feed=rss2");
  feed.load(function(result) {
    $scope.$apply(function(){
      $scope.entries = result.feed.entries;
    })
  });
});
请注意,由于范围从外部角度更改,因此需要调用
$apply
来通知Angular

一些注意事项,首先需要将以下脚本添加到文档中

  • angular-sanitize.min.js
然后,有必要手动引导angular应用程序,因为必须首先加载GoogleFeedAPI

google.load("feeds", "1");
google.setOnLoadCallback(function(){     
    angular.bootstrap(document.body, ['app']);
});
由于提要包含html,因此可以将ngSanitize模块声明为依赖项

var app = angular.module('app', ['ngSanitize']);
要在提要中显示条目,您可以使用
ngRepeater
对接收到的条目进行迭代,当然,还可以使用
ng bind html
指令清理html

<div ng-repeat='entry in entries'>
  <h1>{{entry.title}}</h1>
  <div ng-bind-html= "entry.content"></div>
</div>

{{entry.title}

或使用JSONP的更短版本:
$http.JSONP('http://ajax.googleapis.com/ajax/services/feed/load“,{params:{v:'1.0',q:”,回调:'JSON_callback'})。。参考:我刚刚根据@BettySt的想法写了一篇关于如何做到这一点的文章@Bettys你不能在Angular的内部使用它,因为它找不到$http@CodedContainer您需要在控制器中插入$http;)然后你可以这样使用它: