简体   繁体   English

获取用于jQuery的php url变量

[英]Get php url variable for use in jquery

Okay so I have an html5 audio player that i built with jquery however i need to get the track url from the variable in the url with a get request so that it can then be used in the jquery script. 好的,所以我有一个用jQuery构建的html5音频播放器,但是我需要使用get请求从url中的变量获取音轨url,以便可以在jQuery脚本中使用它。 Not sure how to do it. 不知道该怎么做。 I have the jquery in a seperate file to the markup for easy embedding for users. 我将jquery放在一个单独的文件中,用于标记,以便于用户嵌入。 The url will look like www.mysite.co.uk/player/player.html?url=testing123.mp3. 该网址将类似于www.mysite.co.uk/player/player.html?url=testing123.mp3。

I can easily get the variable for use in the markup to show the name of the artist etc with PHP but not sure how to do it for the jquery script. 我可以很容易地在PHP中使用变量来显示标记的名称,例如PHP,但不确定如何为jquery脚本执行此操作。 I have had a look around but no luck. 我环顾四周,但没有运气。

Heres the relevent jquery 继承关系jQuery

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

I shouldnt think anymore code is needed but if it is just ask. 我不认为需要更多的代码,但是如果只是问问。

head

<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>
<?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>

And remove song from your .js 并从您的.js删除歌曲

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM