2

我正在开发其中 XML 是我的播放列表的视频播放器。这是代码:

$crxml=file_get_contents('http://spoti.com/latest.xml/?lang=en');    
   $rss=new SimpleXMLElement($crxml);
  $playlistitem=1;
foreach($rss->channel->item as $post)

if($playlistitem<=8)

echo '<ul>';
echo '<li class="xtitle">'.$post->title.'</li>';
echo '<li class="xdesc">'.$post->description.'</li>';    
$dc=$post->children('http://search.yahoo.com/mrss/');
echo '<li class="xthumb">'.$dc->thumbnail->attributes()->url.'</li>';
echo '<li class="xpreview">'.$dc->thumbnail->attributes()->url.'</li>'; 
echo '<li class="xsources_mp4">'.$dc->content->attributes()->url.'</li>';
$dc->content->attributes()->url=preg_replace('/.mp4/','.webm',$dc->content-attributes()->url);
 echo '<li class="xsources_webm">'.$dc->content->attributes()->url.'</li>';
 echo '</ul>';
$playlistitem++;

当用户单击语言时,我想用新内容替换旧内容所有条目都替换为新条目

4

1 回答 1

0

一个例子

if(isset($_POST["lang"]))
    {
       $lang = $_POST["lang"];
    } else {
       $lang = "eng";
    }
$crxml=file_get_contents('http://spoti.com/latest.xml/?lang='.$lang);    
$rss=new SimpleXMLElement($crxml);
$playlistitem=1;

foreach($rss->channel->item as $post) {
    if($playlistitem<=8) {
        echo '<ul id="playlist">';
        echo '<li class="xtitle">'.$post->title.'</li>';
        echo '<li class="xdesc">'.$post->description.'</li>';    
        $dc=$post->children('http://search.yahoo.com/mrss/');
        echo '<li class="xthumb">'.$dc->thumbnail->attributes()->url.'</li>';
        echo '<li class="xpreview">'.$dc->thumbnail->attributes()->url.'</li>';
        echo '<li class="xsources_mp4">'.$dc->content->attributes()->url.'</li>';
        $dc->content->attributes()->url=preg_replace('/.mp4/','.webm',$dc->content-attributes()->url);
        echo '<li class="xsources_webm">'.$dc->content->attributes()->url.'</li>';
        echo '</ul>';
        $playlistitem++;
    }
}

然后在页面上的jQuery中有一个带有语言的选择框,称为#langSelect

$('#langSelect').change( function() {
    var langSelected = $(this).val();

    $("#playlist").load("<?php echo $_SERVER['PHP_SELF']."?uid=".time(); ?> #playlist", {lang: langSelected});
});

要调试尝试使用这个:

$('#lang').change( function() {
    var langSelected = $(this).val();
    alert('Selected language: '+langSelected);
    var url = '<?php echo $_SERVER['PHP_SELF']."?uid=".time(); ?>';
    alert('Ajax POST URL is: '+ url);
    $("#playlist").load(url+" #playlist", {lang: langSelected}, function(response, status, xhr) {
            alert(status);
            alert(response);
        }
    });
});
于 2012-04-12T19:21:10.860 回答