如何在php中从HTML或javascript调用参数


how to call parameters from html or javascript in php

在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文件(歌曲。php)我需要替换代码,并调用变量从脚本从html页面或javascript文件:

$t = new streaminfo('http://90.100.100.10:8000/xxx');

$t = new streaminfo('http://'+$radioURL+':'+$radioPort');

请帮! !…如何继续?

在你的song.php中,你几乎是对的。
只要使用POST接收到的数据…并使用PHP字符串连接而不是Javascript字符串连接:)

$radioURL = isset($_POST['currentradiourl') ? $_POST['currentradiourl' : '';
$radioURL = isset($_POST['currentradioport') ? $_POST['currentradioport' : '';
$t = new streaminfo('http://' . $radioURL . ':' . $radioPort);

因为这是一个帖子,你发布的变量:currentradiourlcurrentradioport。在你的PHP文件中,你可以这样做:

$radioURL = $_POST['currentradiourl'];
$radioPort = $_POST['currentradioport'];
$t = new streaminfo("http://{$radioURL}:{$radioPort}");