在html页面中我有脚本:
<script type="text/javascript" src="player.js"></script>
<head>
<script>
$radioURL = "90.100.100.10";
$radioPort = "8000/xxx;
</script>
</head>
....
在javascript(player.js)中,我有:
//get current song
$.ajaxSetup({ cache: false });
var dataString = {
'currentradiourl' : $radioURL,
'currentradioport' : $radioPort,
};
$.ajax({
type: "POST",
url: "song.php",
data: dataString,
success: function(data)...
最后,在php文件(song.php)中,我需要替换代码,并从html页面或javascript文件中调用脚本中的变量:
$t = new streaminfo('http://90.100.100.10:8000/xxx');
与
$t = new streaminfo('http://'+$radioURL+':'+$radioPort');
请帮忙!!! ......怎么办?
答案 0 :(得分:0)
在你的song.php
中,你几乎是对的
仅使用POST
收到的数据...并使用PHP字符串连接而不是Javascript one:)
$radioURL = isset($_POST['currentradiourl') ? $_POST['currentradiourl' : '';
$radioURL = isset($_POST['currentradioport') ? $_POST['currentradioport' : '';
$t = new streaminfo('http://' . $radioURL . ':' . $radioPort);
答案 1 :(得分:0)
由于它是一个帖子,您可以发布变量:currentradiourl
和currentradioport
。在PHP文件中,您可以这样做:
$radioURL = $_POST['currentradiourl'];
$radioPort = $_POST['currentradioport'];
$t = new streaminfo("http://{$radioURL}:{$radioPort}");