我使用jQuery从以下API获取数据 (https://swapi.co/api/people/)。
到目前为止,我可以得到所有的主要数据,“名称”、“高度”、“质量”等等。但是,当我试图得到“主世界”、“电影”、“物种”、“车辆”、“星舰”的值时却只显示它所指的网址,我不知道该用什么方法在这些URL中获取值。
我的代码:
$(document).ready(function() {
function getStarWars() {
$.ajax({
dataType: 'json',
type: 'GET',
async: true,
url: 'https://swapi.co/api/people/1/',
success: function(datos) {
if (datos != null) {
console.log(datos.name);
console.log(datos.homeworld);
console.log(datos.films);
console.log(datos.species);
}
},
error: function(xhr, status) {
alert('Sorry, i have a problem');
}
});
}
getStarWars();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</div>