Mindfuc Mindfuc - 3 years ago 91
Ajax Question

How to load json array

Im trying to load person data from api : www.swapi.co .
However i dont know how can i load movies titles
instead of their api adress.

$(function(){

var list = $('.list');
var submit = $('.submit-people');
var people = '1';

submit.on('click',function(){
people++;
list.empty();

$.ajax({

type: 'GET',
url: 'https://swapi.co/api/people/' + people + '/',

success: function(data) {

list.append('<li>Name:' + data.name + '</li>');
list.append('<li>Height:' + data.height + '</li>');
list.append('<li>Mass:' + data.mass + '</li>');
list.append('<li>Gender:' + data.gender + '</li>');
list.append('<li>Movies:' + data.films + '</li>');

}

})

})


my current code is here : https://jsfiddle.net/wtpy71d7/2/

really thanks for any help or suggestions

Answer Source

This might help you.

success: function(data) {
     ...
     for(var i = 0; i< data.films.length; i++ )
          $.ajax({
             type: "get",
             url: data.films[i],

             success: function (data) {
                list.append('<li>Movies:' + data.title + '</li>');
             }
          });
     }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download