如何使用JSONP在AngularJS资源 [英] how to use JSONP in AngularJS resource

查看:99
本文介绍了如何使用JSONP在AngularJS资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图导入JSON对象到变量。我按照教程使用的服务。

I'm trying to import json object into variable. I use the services according to tutorial.

我收到意外的标记错误,因为我不应该使用 $ scope.news = JsonSource.feed(); - 但我真的不知道我应该怎么使用。我一派,搜索3小时我发现只有$ HTTP。或$ JSON。答案,但我觉得,它可以做更容易 - 更清晰。

I receive unexpected token error, because i shouldn't use $scope.news = JsonSource.feed(); - but I really don't know what should I use. I googled and searched 3 hours I find only $http. or $json. answers, but I feel, that it could be done easier - clearer.

(完美的解决方案将是 $ scope.news = JsonSource.feed()项

(The perfect solution would be $scope.news = JsonSource.feed().entries ;D

services文件:

The services file:

var AAAServices = angular.module('AAAServices', [
    'ngResource'
]);

AAAServices.factory('JsonSource', ['$resource',
  function($resource) {
    return $resource('https://www.facebook.com/feeds/page.php', {}, {
      feed: {method:'JSONP', {format: 'json', id:'459908', callback : JSON_CALLBACK}, isArray:false}
      });
  }]);

这些控制器文件:

The controllers file:

var AAAControllers = angular.module('AAAControllers', [])
AAAControllers.controller('newsCtrl', ['$scope', 'JsonSource', 
  function newsCtrl($scope, JsonSource) {
     $scope.news = JsonSource.feed();
}]);

JSON文件(几乎; D)

the json file (almost ;D)

{
   "title": "Tytuł",
   "link": "https:\/\/www.facebook.com\/",
   "entries": [
      {
         "title": " news 1",
         "id": "1"
      },
      {
         "title": " news 2",
         "id": "2"
     }
   ]
}

编辑:

我改变$资源('file.json到 https://www.facebook.com/供稿/ page.php - 这样你就可以检查它是否是JSON或JSONP ...

i change $resource('file.json into https://www.facebook.com/feeds/page.php - so you can check if it is json or jsonp...

推荐答案

这是为那些答案,谁认为(我),如果事情在浏览器中运行它应该在服务器脚本。

This is the answer for those, who thinks (as me) that if something works in browser it should work in server scripts.


  1. 的Facebook给出了墙内容非常漂亮的JSON:

https://www.facebook.com/feeds/ ?page.php格式= JSON和ID = XXXX


  1. 但是你不能从得到的NodeJS它 - 因为跨域策略,限制

更多是在这里:加载的Facebook墙上饲料JSON问题

所以,现在我要寻找JSONP流的Facebook涂鸦墙......唉......

So, now i have to search for jsonp stream for facebook wall... Sigh....

这篇关于如何使用JSONP在AngularJS资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆