0

好的,所以我有一个用 jquery 构建的 html5 音频播放器,但是我需要使用 get 请求从 url 中的变量获取轨道 url,以便它可以在 jquery 脚本中使用。不知道该怎么做。我将 jquery 放在一个单独的文件中以方便用户嵌入标记。该网址将类似于 www.mysite.co.uk/player/player.html?url=testing123.mp3。

我可以很容易地获取用于标记的变量,以使用 PHP 显示艺术家的姓名等,但不确定如何为 jquery 脚本执行此操作。我环顾四周,但没有运气。

这是相关的jquery

song = new Audio('THIS IS WHERE THE GET VARIABLE NEEDS TO BE');

我不应该认为需要更多的代码,但如果只是问的话。

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

<?php $url = $_GET['url']; ?> 

<script> // Before jQuery
    var song = new Audio(`<?php echo($url); ?>`);
</script>`
<script type="text/javascript" src="http://newbornsounds.co.uk/player/src/js/js.js"></script>
<script type="text/javascript" src="http://newbornsounds.co.uk/player/src/js/html5slider.js"></script>
4

1 回答 1

4
<?php
$url = $_GET['url']; // Avoid this way! Need to be as safe as possible.
?>

[...]

<head>
    [...]

    <script> // Before jQuery
        var song = new Audio(`<?php echo($url); ?>`);
    </script>`

    [...]
</head>

并从您的歌曲中删除歌曲.js

于 2012-07-03T01:33:06.187 回答