通过node.js访问JSON API
Accessing JSON API via node.js
我想访问JSON上的
"https://blockchain.info/tx-index/"+txs[i]+"?format=json"
但是每次我尝试使用请求,http或https模块访问它时,我似乎永远无法获得任何信息。这个回调函数从来没有被调用过,而且据我所知,这个函数没有返回任何东西。
既然我显然是javascript的白痴,你能帮我吗?
编辑:我也尝试了另一种方法描述在这里,但它似乎也不起作用。它总是返回undefined
function httpGet(url) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET",url,false);
xmlHttp.send();
return xmlHttp.resonpose;
}
编辑:完整循环代码:
index = 0;
txs = info.x.txIndexes;
for (i = 0; i < txs.length; i++) {
console.log(i);
request.get("https://blockchain.info/tx-index/"+txs[i]+"?format=json&cors=true", function(error,response,body) {
console.log("body");
txs[index] = JSON.parse(body);
index++;
});
var time = Date.now() + 1000;
while (Date.now() < time)
var a = true;
txs[i] = txt;
}
function httpGet(url) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET",url,false); xmlHttp.send(); return xmlHttp.resonpose; }
resonpose
拼写为response
,但更常用的属性名称是responseText
。
您尝试使用request.get
失败的原因完全不同,但这是由这个问题所涵盖的,因为您的加载事件处理程序正在使用i
的错误值。
相关文章:
- Backbone.js restful json API design
- 如何在ng-reeat中使用ng-switch来编辑JSON API数据
- 从JSON API结果迭代时未定义
- 将JSON API数据获取到html
- json-api和错误结果:无法读取属性'长度'的未定义
- 使用Angular JS for WordPress JSON API使用JSON操作数据
- 如何限制JSON API WordPress插件
- 如何在JavaScript中使用JSON API
- Jquery Json Api
- 如何在sails.js上同时构建html和json api
- Angular promise从JSON API返回不正确的数据
- 使用Jquery将JSON API请求的元素传递给数组
- Javascript 客户端框架与 Rails JSON API - 如何进行集成测试
- JSON API 不会在 jquery getJSON 中返回任何结果
- 用于 Rails JSON API 的有用 nodejs 库
- 使用 ng-repeat 过滤 JSON API
- 在快速应用中将 JSON API 的对象拆分为块
- 如何制作 json api
- Javascript:具有多个查询参数的嵌套 JSON api 请求
- {还没有答案}从 YouTube JSON API 获取评论分数