1

I am creating a football website for my college project and I am using apis to pull the data on teams. On my home page I am displaying details about all teams using a jquery request.

function getTeams() {
        $.ajax(
                {
                    type: 'GET',
                    dataType: 'json',
                    url: "http://api.football-data.org/v1/competitions/426/teams",
                    processData: true,
                    success: function (data, status) {
                        var trHTML = '';
                        $.each(data.teams, function (key, item) {
                            //$('<option>', { text: item.TeamName, id: item.ID }).appendTo('#lstTeams');
                            trHTML += '<tr class="info"><td>' + item.name +
                            '</td><td>' + item.code +
                            '</td><td>' + item.shortName +
                            '</td><td>' + item.squadMarketValue +
                            '</td><td>' + item.crestURL +

                            '</td></tr>';

                        })

I would like to be able to select a team and display more details about them on another page. The trouble I am having though is there is no ID being pulled even though each team has an ID. Any idea how to grab this ID and pull it in?

David Regan
  • 41
  • 1
  • 11
  • Hi, API call don't provide any ID. But it's not big deal. U can generate an ID for every item in your $.each statement. Learn more about uuid –  Mar 10 '17 at 19:20
  • Does each item has an `ID` property ? Each item should have a unique key using which you can get more details – Shyju Mar 10 '17 at 19:33
  • 1
    Yes each team has an id in the url to get more detail e.g. http://api.football-data.org/v1/teams/66/players is for Man utd or http://api.football-data.org/v1/teams/71/players is for Man city but I don't know how to extract this Id. – David Regan Mar 10 '17 at 19:41
  • 3
    Possible duplicate of [regex to get the number from the end of a string](http://stackoverflow.com/questions/6340180/regex-to-get-the-number-from-the-end-of-a-string) – Sam Axe Mar 10 '17 at 19:45

0 Answers0