I have problem importing images of Json File on HTML Table
-
Hello, I successfully loaded the json responses into an HTML table. However, I am having a problem displaying the images of the json variables. I could only display the links. Here is the output:
Home Team Match Date Away Team
https://media-3.api-sports.io/football/teams/2939.png 2023-01-22T20:30:00+03:00 https://media-3.api-sports.io/football/teams/2934.png
https://media-3.api-sports.io/football/teams/2938.png 2023-01-26T21:00:00+03:00 https://media-3.api-sports.io/football/teams/2939.png
https://media.api-sports.io/football/teams/2931.png 2023-02-03T17:00:00+03:00 https://media.api-sports.io/football/teams/2939.png
https://media.api-sports.io/football/teams/2937.png 2023-02-09T19:30:00+03:00 https://media-3.api-sports.io/football/teams/2939.png
https://media-3.api-sports.io/football/teams/2939.png 2023-02-17T17:00:00+03:00 https://media-3.api-sports.io/football/teams/2936.pngHere is a sample of the json file:
array (
'api' =>
array (
'results' => 10,
'fixtures' =>
array (
0 =>
array (
'fixture_id' => 932017,
'league_id' => 4633,
'league' =>
array (
'name' => 'Pro League',
'country' => 'Saudi-Arabia',
'logo' => 'https://media-3.api-sports.io/football/leagues/307.png',
'flag' => 'https://media-3.api-sports.io/flags/sa.svg',
),
'event_date' => '2023-01-22T20:30:00+03:00',
'event_timestamp' => 1674408600,
'firstHalfStart' => NULL,
'secondHalfStart' => NULL,
'round' => 'Regular Season - 14',
'status' => 'Not Started',
'statusShort' => 'NS',
'elapsed' => 0,
'venue' => 'Mrsool Park',
'referee' => NULL,
'homeTeam' =>
array (
'team_id' => 2939,
'team_name' => 'Al-Nassr',
'logo' => 'https://media.api-sports.io/football/teams/2939.png',
),
'awayTeam' =>
array (
'team_id' => 2934,
'team_name' => 'Al-Ettifaq',
'logo' => 'https://media.api-sports.io/football/teams/2934.png',
),
'goalsHomeTeam' => NULL,
'goalsAwayTeam' => NULL,
'score' =>
array (
'halftime' => NULL,
'fulltime' => NULL,
'extratime' => NULL,
'penalty' => NULL,
),
),And here is the code for impor
-
Hello, I successfully loaded the json responses into an HTML table. However, I am having a problem displaying the images of the json variables. I could only display the links. Here is the output:
Home Team Match Date Away Team
https://media-3.api-sports.io/football/teams/2939.png 2023-01-22T20:30:00+03:00 https://media-3.api-sports.io/football/teams/2934.png
https://media-3.api-sports.io/football/teams/2938.png 2023-01-26T21:00:00+03:00 https://media-3.api-sports.io/football/teams/2939.png
https://media.api-sports.io/football/teams/2931.png 2023-02-03T17:00:00+03:00 https://media.api-sports.io/football/teams/2939.png
https://media.api-sports.io/football/teams/2937.png 2023-02-09T19:30:00+03:00 https://media-3.api-sports.io/football/teams/2939.png
https://media-3.api-sports.io/football/teams/2939.png 2023-02-17T17:00:00+03:00 https://media-3.api-sports.io/football/teams/2936.pngHere is a sample of the json file:
array (
'api' =>
array (
'results' => 10,
'fixtures' =>
array (
0 =>
array (
'fixture_id' => 932017,
'league_id' => 4633,
'league' =>
array (
'name' => 'Pro League',
'country' => 'Saudi-Arabia',
'logo' => 'https://media-3.api-sports.io/football/leagues/307.png',
'flag' => 'https://media-3.api-sports.io/flags/sa.svg',
),
'event_date' => '2023-01-22T20:30:00+03:00',
'event_timestamp' => 1674408600,
'firstHalfStart' => NULL,
'secondHalfStart' => NULL,
'round' => 'Regular Season - 14',
'status' => 'Not Started',
'statusShort' => 'NS',
'elapsed' => 0,
'venue' => 'Mrsool Park',
'referee' => NULL,
'homeTeam' =>
array (
'team_id' => 2939,
'team_name' => 'Al-Nassr',
'logo' => 'https://media.api-sports.io/football/teams/2939.png',
),
'awayTeam' =>
array (
'team_id' => 2934,
'team_name' => 'Al-Ettifaq',
'logo' => 'https://media.api-sports.io/football/teams/2934.png',
),
'goalsHomeTeam' => NULL,
'goalsAwayTeam' => NULL,
'score' =>
array (
'halftime' => NULL,
'fulltime' => NULL,
'extratime' => NULL,
'penalty' => NULL,
),
),And here is the code for impor
Looks like an old codebase using PHP and jQuery. Just FYI, rather than dump all your code, perhaps start with just the relevant bits? It shows us you put some effort into this. Anywho, that JSON object will only have a string in it. If that string is a path to an image, you'll have to output that path in its
src
attribute, similar to the way you're building out that table.const output = `
`;
element.innerHTML += output;Note: There are better ways to go about this, but I'll save that for a different day.
Jeremy Falcon