javascript - PHP 输出未出现在 HTML 中

标签 javascript php html css spotify

我编写了一些代码来发布一个 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/

相关文章:

php - 带时间戳的数据库,显示不同的月份

当选项卡栏存在时,在 iOS 中的 Safari 中旋转到横向时 HTML 元素消失

html - 在我的网站上定位关于我的部分

javascript - 停止点击子项目

php - 检查网址中是否包含某些单词,然后显示

javascript - 如何在 ASP.NET 中显示消息框?

php - CakePHP 3 - 捕获错误

html - 响应式目录页面 - 表格与分区?

javascript - Rails 在 application.js 中找不到文件

javascript - AngularJS ngShow 和焦点