【问题标题】:Pulling data from private API using xmlhttprequest使用 xmlhttprequest 从私有 API 中提取数据
【发布时间】:2017-10-02 16:32:56
【问题描述】:

我需要一些帮助来尝试从私有 api 中提取数据。这是我的代码

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.open("GET", "https://pubgtracker.com/api/profile/pc/silentsushix3?api=bc98fb9b-31be-4df4-ac36-fff4c5230b04", true);
xhr.send();

console.log(xhr.status);
console.log(xhr.response);    

当这部分脚本运行时,它会返回 200 状态但未定义的响应。

在我的一生中,我无法弄清楚如何提取任何特定数据,或者根本无法提取任何数据。任何帮助将不胜感激。

【问题讨论】:

标签: javascript api xmlhttprequest


【解决方案1】:

这可能会有所帮助...

    xhr.onreadystatechange = function () {
            if (xhr.readyState < 4)
                console.log("Loading...");
            else if (xhr.readyState === 4) {
                if (xhr.status == 200 && xhr.status < 300)
                {
                    console.log(xhr.responseText);
                } 
            }
        }

【讨论】:

  • 也许可以添加更多解释,说明这有何不同以及 OP 的核心错误是什么?
  • Awesome Ali,效果很好。在我能够解析信息并提取所选信息之后!多谢你们。我会将其余代码发布给将来需要的人。
猜你喜欢
  • 2012-01-29
  • 1970-01-01
  • 2015-02-07
  • 1970-01-01
  • 2022-11-16
  • 2015-11-13
  • 2021-11-24
  • 2017-04-16
  • 2021-09-25
相关资源
最近更新 更多