我正在构建一个应用程序,以显示骑行中的所有代表。我似乎无法显示图片。我在做什么错了?
我试图这样调用网址:
const img = document.createElement('img');
img.src = `http://represent.opennorth.ca/postcodes/K2H6G7/${representatives_centroid.photo_url}`
这不能为我提供以前遇到的错误,但照片不会显示。
var data = JSON.parse(this.response);
data.representatives_centroid.forEach(representatives_centroid => {
const card = document.createElement('div');
card.setAttribute('class', 'card');
const img = document.createElement('img');
img.src = `http://represent.opennorth.ca/postcodes/K2H6G7/${representatives_centroid.photo_url}`
const p1 = document.createElement('p');
p1.textContent = `${representatives_centroid.party_name} ${representatives_centroid.elected_office} ${representatives_centroid.first_name} ${representatives_centroid.last_name}`
const p2 = document.createElement('p');
p2.textContent = `${representatives_centroid.district_name}`
container.appendChild(card);
card.appendChild(img);
card.appendChild(p1);
card.appendChild(p2);
});