我编写了一些代码来发布一个 PHP 文件的输出,该文件显示了我最近在 Spotify 上听过的音乐。
HTML、CSS 和 JS(用于 spotify.php 文件)包含在此 fiddle. 中
我的 index.php 文件中的 JS 是:
<script type="text/javascript">
function get_spotify() {
$.ajax({
type: 'POST',
url: 'https://theobearman.com/cv/modules/spotify.php',
data: {
request: 'true'
},
success: function(reply) {
$('.now-playing').html("" + reply + "");
}
});
}
window.onload = get_spotify;
</script>
我的问题是 .php 文件的输出没有显示在 my website 上的“音乐”标题下。 .
这几天前还能用,所以我不确定为什么现在不能用了。
在此先感谢您的帮助,
西奥。
最佳答案
尝试
$(document).ready(function() {
get_spotify();
});
而不是 window.onload = get_spotify
,它可能在元素呈现在页面上之前运行。
关于javascript - PHP 输出未出现在 HTML 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29815978/