你可以幫我解決問題,並通過REST API獲取數據:REST/XMLHttpRequest的使用JavaScript
信息:獲取用戶//此端點返回有關特定用戶的信息。 HTTP請求 - https://www.codewars.com/api/v1/users/:id_or_username
頁是有效的:https://www.codewars.com/api/v1/users/Luqpa
我使用下面的腳本:
function createRequest() {
var result = null;
result = new XMLHttpRequest();
return result;
}
var req = createRequest(); // defined above
// Create the callback:
req.onreadystatechange = function() {
if (req.readyState != 4) return; // Not there yet
if (req.status != 200) {
// Handle request failure here...
return;
}
// Request successful, read the response
var resp = req.responseText;
// ... and use it as needed by your app.
}
url = "https://www.codewars.com/api/v1/users/Luqpa";
req.open("GET", url, true);
req.send();
var status = req.status;
var status_text = req.statusText;
var xmlDocument = req.responseXML;
console.log(xmlDocument);
console.log(status);
console.log(status_text);
console.log (req);
所有的反應都是null或0
我曾嘗試過各種possiblities和閱讀其他教程,並沒有找到解決方案。請,建議我如何解決它,並從頁面獲得信息....
在此先感謝。