栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过Angular从Firebase托管获取JSONP文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过Angular从Firebase托管获取JSONP文件

您需要

?callback=JSON_CALLBACK
在传递给的URL中指定
$http.jsonp

从Angular的

$http.jsonp
文档中:

jsonp(url, [config]);Shortcut method to perform JSONP request.ParametersParam   Type    Detailsurl     string  Relative or absolute URL specifying the destination of the request.The name of the callback should be the string JSON_CALLBACK.

最后一行是您所缺少的。

一个简单的示例(使用Firebase数据库,而不是Firebase托管):

var app = angular.module('myapp', []);app.controller('mycontroller', function($scope, $http) {  var url = 'https://yourfirebase.firebaseio.com/25564200.json';  $http.jsonp(url+'?callback=JSON_CALLBACK').then(    function(resp){      console.log(resp.data); // your object is in resp.data    },    function(err){        console.error(err.status)    }  );  });

如果您希望看到它正常工作:http :
//jsbin.com/robono/1/watch?js,console



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/613921.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号