我正在尝试这样做,但我发现的只是四舍五入到最接近的整数。我想知道是否有办法用 math.round 来做到这一点,或者是否有不同的解决方案。谢谢!
我对js比较陌生。我希望能够使用纯 JavaScript 从外部 url 解析 json。目前我正在使用
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
function statsget() {
var uname = document.getElementById("nameget").value;
var data = getJSON(`https://www.reddit.com/user/${uname}/circle.json`);
var stats = JSON.parse(data);
alert(data.is_betrayed);
}
Run Code Online (Sandbox Code Playgroud)
然而这不起作用。有人能帮我解决这个问题吗?谢谢!