流星js使用http.get从网页检索json数据 [英] Meteor js use http.get to retrieve json data from a webpage

查看:104
本文介绍了流星js使用http.get从网页检索json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在客户端使用HTTP.get检索一些json数据并将其存储为字符串?

Is it possible to use HTTP.get on the client side to retrieve some json data and store it as a string?

我需要从此站点获取JSON https://blockchain.info/address/15cNko3ZtmYCba8GoaYsZ6GWFy1 ?format = json 并将其存储为字符串以供以后解析.

I need to get the JSON from this site https://blockchain.info/address/15cNko3ZtmYCba8GoaYsZ6GWFy1VCLgFji?format=json and store it as a string for later parsing.

上述钱包的站点地址是随机选择的.

The above site address for the wallet was chosen at random.

推荐答案

尝试在浏览器控制台的应用程序开发"选项卡中键入$.ajax("https://blockchain.info/address/15cNko3ZtmYCba8GoaYsZ6GWFy1VCLgFji?format=json");.

Try typing $.ajax("https://blockchain.info/address/15cNko3ZtmYCba8GoaYsZ6GWFy1VCLgFji?format=json"); in your browser console in your application development tab.

您可能会收到此错误作为响应:

You're likely to receive this error as response :

XMLHttpRequest cannot load https://blockchain.info/address/15cNko3ZtmYCba8GoaYsZ6GWFy1VCLgFji?format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

这是一个与CORS相关的问题,它本身就是一个完整的话题,因此,我建议您谷歌搜索并理解其含义.

This is a CORS related issue which is a whole topic on itself so I suggest you google this and understand its implications.

接下来,如果您可以在尝试从中获取json的域上控制CORS设置,则需要允许来自Web应用程序域的跨源请求,这在使用Amazon S3存储桶(另一个Web)时是可行的您设计的应用程序,等等...

Next, if you can control CORS settings on the domain where you're trying to fetch json from, then you need to allow cross origin requests from your web application domain, this is possible when using an amazon S3 bucket, another web application you designed, etc...

如果不能,那么恐怕您将不得不使用Meteor.method客户端来访问您的Meteor服务器,并在其中使用HTTP来获取json.然后将其发送回Meteor客户端

If you can't, then I'm afraid you'll have to use a Meteor.method client side to reach your Meteor server where you'll fetch the json with HTTP.get then send it back to the Meteor client.

这篇关于流星js使用http.get从网页检索json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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