如何在json中仅使用javascript使用api

How to use api in json with only javascript

本文关键字:javascript 使用 api json      更新时间:2023-09-26

我想通过使用java脚本从API链接获取数据。我只想在纯javascript中做这个。

使用JavaScript函数:

var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { 
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
        callback(xmlHttp.responseText);
}
xmlHttp.open("GET", url, true); 
xmlHttp.send(null);