我正在尝试将我的查询从 PHP 转换为 Ajax。
我目前正在使用它从 PHP 返回歌曲 ID 结果。
<a href="javascript:songinfo(<?php echo $currentSong->ID; ?>)" title="Lyrics and song info"></a><?php echo $currentSong->title; ?>
使用这个我得到这样的东西
http://chennaichristianradio.com/PHP/web/songinfo.php?songID=5506
如何从 Ajax 中得到相同的结果,并得到与上面相同的返回地址?最后的歌曲 ID 是从我的数据库中提取的信息。这将用于某人单击此链接以打开一个新页面,该页面显示歌曲 ID 5506 的内容。
你可以在这里看到我正在尝试使用我当前的 PHP 做的事情。只需点击“歌曲信息”按钮之一。
http://chennaichristianradio.com/PHP/web/history.php
我尝试使用 AJAX 进行以下操作但没有成功。不要对我的代码大笑,因为我只是在学习 AJAX 和 PHP。
脚本
document.getElementById('ID').innerHTML = aj_ID "<a href="songinfo.php?songID=+ aj_results[7] + >"
并在 HTML
<a href="javascript:songinfo(<div id="id"></div>)" title="Lyrics and song info"><img src="../../images/info.png" alt="Track information" width="70" height="22" border="none" title="Song Info and Lyrics" /></a>
谢谢您的帮助
编辑:这是我的 ajax 脚本
<?php
//Sam Broadcaster - AJAX Module - Send Artist/Title/Duration and Seconds remaining to getXMLHTTPRequest
//Written, cobbled together by wilksy101. This code contain code sourced from the support forums and stuff written myself
// Change to your database user name
$username="************";
//Change to your database password
$password="************";
// Change to your database name
$database="************";
// Connect to the database
mysql_connect('ccronline.dyndns.info',$username,$password);
// Handle an error
@mysql_select_db($database) or die( "Unable to select database");
// Build Sql that returns the data needed - change this as required.
$sql = "SELECT songlist.*, historylist.listeners as listeners, historylist.requestID as requestID, historylist.date_played as starttime FROM historylist,songlist WHERE (historylist.songID = songlist.ID) AND (songlist.songtype='S' OR songlist.songtype='C' OR songlist.songtype='N') ORDER BY historylist.date_played DESC LIMIT 1";
// Store results in result object
$result = mysql_query($sql);
//store values in vars for calculation for array creation
$curPlay = mysql_query("SELECT * FROM historylist ORDER BY date_played DESC LIMIT 1");
$curPlayRow = mysql_fetch_assoc($curPlay);
if (!$curPlay) { echo( mysql_error()); }
$dt_duration = mysql_result($result,$i,'duration');
$title= mysql_result($result,$i,'title');
$artist= mysql_result($result,$i,'artist');
$album= mysql_result($result,$i,'album');
$picture= rawurlencode(mysql_result($result,$i,'picture'));
$lyrics= mysql_result($result,$i,'lyrics');
$ID= mysql_result($result,$i,'ID');
$curtime = time();
$timeleft = $starttime+round($dt_duration/1000)-$curtime;
$secsRemain = (round($dt_duration / 1000)-($curtime-$starttime));
//build array to return via getXMLHTTPRequest object - you can include more vars but remeber to handle them
//correcty in the useHttpResponse function
$Aj_array = $dt_duration . '|' . $secsRemain . '|' . $title . '|' . $artist .'|' . $album .'|' . $picture .'|' . $lyrics .'|' . $ID;
//we are using the text response object - which i think is easier for small data return
//just echo the array - not so much AJAX rather AJA ??
echo $Aj_array
?>