こんにちは、私は作業しているプロジェクトに問題があります。 私はこの作業を得るためにいくつかの方法を試しましたが、最高の私はそれがPHPでエコーすると思う。だから、ここで私は(ライン20および21に)やった方法です:jsでPHPを実装するための助けが必要
\t <script type="text/javascript">
\t jQuery(document).ready(function($) {
\t "use strict";
\t var changeTrack = function changeTrack(event) {
\t var current = myPlaylist.current,
\t \t playlist = myPlaylist.playlist;
\t $.each(playlist, function (index, obj) {
\t if (index == current) {
\t $("#nowPlaying .artist-name").html(obj.artist);
\t $("#nowPlaying .track-name").html(obj.title);
\t }
\t });
\t };
\t
\t \t var myPlaylist = new jPlayerPlaylist({
\t \t \t jPlayer: "#jquery_jplayer_1",
\t \t \t cssSelectorAncestor: "#jp_container_1",
\t \t }, [
\t \t \t {
\t \t \t \t artist:"<?php echo $artist; ?>",
\t \t \t \t title:"<?php echo $track; ?>",
\t \t \t \t mp3:"http://<?php echo $ipport; ?>/api/v1/bot/i/<?php echo $inst; ?>/stream/<?php echo $sinusbot->getWebStreamToken($inst); ?>"
\t \t \t }
\t \t ],{
\t \t \t playlistOptions: {
\t \t \t enableRemoveControls: false,
\t \t \t autoPlay: true
\t \t \t },
\t \t \t swfPath: "assets/jplayer/jplayer",
\t \t \t supplied: "ogv, m4v, oga, mp3",
\t \t \t wmode: "window",
\t \t \t useStateClassSkin: true,
\t \t \t autoBlur: false,
\t \t \t smoothPlayBar: false, //removes bar jittery
ready: changeTrack,
\t \t play: changeTrack
\t \t });
\t });//end .ready
\t </script>
require 'getSong.php';
とし、
include("getSong.php");
でPHPファイルを含めるようにtryiedが、そのだけでサイトをクラッシュ。
<?php
error_reporting('E_ERROR');
include("sinusbot.class.php");
include("config.php");
$sinusbot = new SinusBot($ipport);
$sinusbot->login($user, $passwd);
$status = $sinusbot->getStatus($inst);
$track = (($status["currentTrack"]["type"] == "url") ? $status["currentTrack"]["tempTitle"] : $status["currentTrack"]["title"]);
$artist = $status["currentTrack"]["tempArtist"];
$name = $track;
$track = preg_replace('^ ^', '+', $track);
if(!empty($artist)) {
echo $name." from ".$artist;
} else {
echo $name;
}
が、これは自動的にトラック名/アーティストを取得するには、JSからこの程度... 私が欲しいです何を君たちに伝え忘れた:ここではPHPファイルです。
私は、ここにgetSong.phpのために使用された古い方法を置くJSます:
<script type="text/javascript">
function loadSong() {
\t \t var xhttp = new XMLHttpRequest();
\t \t xhttp.onreadystatechange = function() {
\t \t \t if (xhttp.readyState == 4 && xhttp.status == 200) {
\t \t \t \t document.getElementById("getSong").innerHTML = "" + xhttp.responseText;
\t \t \t }
\t \t };
\t \t xhttp.open("GET", "getSong.php", true);
\t \t xhttp.send();
\t } \t
function loadImg() {
\t \t var xhttp = new XMLHttpRequest();
\t \t xhttp.onreadystatechange = function() {
\t \t \t if (xhttp.readyState == 4 && xhttp.status == 200) {
\t \t \t \t document.getElementById("getImg").innerHTML = xhttp.responseText;
\t \t \t }
\t \t };
\t \t xhttp.open("GET", "getImg.php", true);
\t \t xhttp.send();
\t }
\t
function loadSearch() {
\t \t var xhttp = new XMLHttpRequest();
\t \t xhttp.onreadystatechange = function() {
\t \t \t if (xhttp.readyState == 4 && xhttp.status == 200) {
\t \t \t \t document.getElementById("search").innerHTML = xhttp.responseText;
\t \t \t }
\t \t };
\t \t xhttp.open("GET", "search.php", true);
\t \t xhttp.send();
\t }
\t
setInterval(function() {
\t loadImg();
\t loadSong();
\t loadSearch();
}, 3500);
</script>
<div id="getImg">Loading...</div>
\t <div id="search">Loading...</div>
\t <div id="getSong">Please Wait...</div>
エラーがありますあなたは得る?あなたのコンソールは何を言いますか? –
私はXAMPPのローカルサイトを使用していますが、php_error_logをチェックしても何も表示されず、Webブラウザのコンソール(Mozilla)にこのエラーがあります:TypeError:document.getElementById(...)is null [詳細] radio: 180:5 \t loadImg/xhttp.onreadystatechange – 1Example
idがgetSongの要素がないようです。 – aynber