`; } }); if (container.innerHTML === '') { container.innerHTML = '
暂无广告
'; } } fetch('https://ay.tj.cn/api_ads.php') .then(response => { if (!response.ok) throw new Error(`请求失败,状态码: ${response.status}`); return response.json(); }) .then(data => { if (Array.isArray(data)) { renderAllAds(data); } else { throw new Error('返回数据格式错误:应为数组'); } }) .catch(error => { console.error('广告加载失败:', error); document.getElementById('ad-container').innerHTML = `
`; });