javascript - 如何使用 Rapidapi 从 json 获取 html 输出?
问题描述
我一直在努力从Json文件和我从 rapidapi 使用的 API 中获取 HTML 表中的输出,但我没有得到任何输出,也没有代码错误。有什么错误吗?任何人请帮助!
$.getJSON(settings).done(function(response){
console.log(response) });
这将日志提供给控制台..但其他事情没有..为什么?我一直试图获得输出 2 天,但失败了。
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title> Title </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script type="text/javascript">
$(function(){
var settings = {
"async": true,
"crossDomain": true,
"url": "rapidapi_url",
"method": "GET",
"headers" :{
"x-rapidapi-host": "API_url",
"x-rapidapi-key": "my_api_key"
}
};
$.getJSON(settings, function(data){
$.each(data.country_stats, function(i, f){
console.log(i);
console.log(f);
var tblrw = "<tr>" + "<td>" + value.country_name + "</td>" + "<td>" + value.cases + "</td>" + "<td>" + value.deaths + "</td>" + "<td>" + value.region + "</td>" + "<td>" + value.total_recovered + "</td>" + "<td>" + value.new_deaths + "</td>" + "<td>" + value.new_cases + "</td>" + "<td>" + value.serious_critical + "</td>" + "<td>" + value.total_cases_per_1m_population + "</td>" + "</tr>"
$(tblrw).appendTo("#tablerw tbody");
});
});
var tblrw = "<tr>" + "<td>" + value.country_name + "</td>" + "<td>" + value.cases + "</td>" + "<td>" + value.deaths + "</td>" + "<td>" + value.region + "</td>" + "<td>" + value.total_recovered + "</td>" + "<td>" + value.new_deaths + "</td>" + "<td>" + value.new_cases + "</td>" + "<td>" + value.serious_critical + "</td>" + "<td>" + value.total_cases_per_1m_population + "</td>" + "</tr>";
$(tblrw).appendTo("#tablerw tbody");
});
</script>
</head>
<body>
<table class="table table-bordered" id="tablerw">
<thead>
<th>Country name</th>
<th>cases</th>
<th>Deaths</th>
<th>Region</th>
<th>Total Recovered</th>
<th>New Deaths</th>
<th>New cases</th>
<th>Serious/Critical</th>
<th>Total cases per 1m</th>
</thead>
<tbody >
</tbody>
</table>
</body>
</html>
解决方案
推荐阅读
- loops - 自动键循环:执行击键 10 次
- xml - XML - XSLT - 获取 CDATA 元素内的文本
- c# - 重新加载页面时出现数据网格错误
- wpf - 我如何才能看到所有控件的主窗口设计器与运行程序时的外观相同?
- math - 如何将一种数字尺度转换为另一种?
- docker - Docker:将外部映射到内部用户(如何应用'--user',如何执行.bashrc)?
- javascript - 如何在调用需要其中一个文件的其他 js 文件之前动态添加文件
- python - 为什么在列表末尾后插入方式在 Python 中起作用?
- angular - 在角材料中展开和折叠表格行
- key - jq中包含'@'和'-'的转义字段名称?