这是我要分离javascript的实际文件。 我怎么告诉javascript在哪里寻找php文件,目前我只能从php文件中执行javascript ..
<?php
date_default_timezone_set('Europe/London');
require_once("DbConnect.php");
$sql = "SELECT `artist`, `title`, `label`, `albumyear`, `date_played`, `duration`,
`picture` FROM historylist ORDER BY `date_played` DESC LIMIT 5 ";
$result = $db->query($sql);
$lastplayed = array();
$i = 1;
while ($row=$result->fetch_object()) {
$lastplayed[$i]['artist'] = $row->artist;
$lastplayed[$i]['title'] = $row->title;
$lastplayed[$i]['label'] = $row->label;
$lastplayed[$i]['albumyear'] = $row->albumyear;
$lastplayed[$i]['date_played'] = $row->date_played;
$lastplayed[$i]['duration'] = $row->duration;
$lastplayed[$i]['picture'] = $row->picture;
$i++;
}
$starttime = strtotime($lastplayed[1]['date_played']);
$curtime = time();
$timeleft = $starttime+round($lastplayed[1]['duration']/1000)-$curtime;
$secsremain = (round($lastplayed[1]['duration'] / 1000)-($curtime-$starttime));
$lastplayedjson = json_encode( $lastplayed );
?>
我希望此部分位于单独的文件中
<script type="text/javascript">
var lastplayedjson = <?php echo $lastplayedjson ?>;
alert( lastplayedjson[1].title );
alert( lastplayedjson[2].title );
alert( lastplayedjson[3].title );
alert( lastplayedjson[4].title );
</script>