angular js jsonp例子dos not works

时间:2013-06-04 14:01:38

标签: angularjs

我在使用角度js jsonp函数时遇到了麻烦,我无法使这个插件工作:

http://plunker.co/edit/xQVBchTYOro1CB979021

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

使用JSONP“hack”,您必须确保服务器的响应包含回调的调用。要使您的示例正常工作,您应该更改prov.json文件,使其如下所示:

angular.callbacks._0({
   "id": "40796308305",
   "about": "The Coca-Cola Facebook Page is a collection of your stories showing how people from around the world have helped make Coke into what it is today.",
   ...
})

JSONP有很多来源,例如:What is JSONP all about?

答案 1 :(得分:0)

使用get代替jsonp,您可以获得可口可乐的详细信息......

 async: function(page) {
  var url = 'prov.json';     
    var promise = $http.get(url).error(function (response, status) {
      alert("fai");
    }).success(function (response, status) {
      alert(response.about);
    }).then(function (response, status) {
      return response.data;           
  });
  return promise;
}};