Salve a tutti ,
premetto conosco poco javascript.
ho trovato in rete questo script .js
praticamente è un temporizzatore che richiama uno script php ogni qualvolta viene inserito un nuovo commento (vedi sotto). Vengo subito al sodo:
oltre al messaggio vorrei che venga passata anche l'immagine presente nell'sql . Ho provato in vari modi ma niente da fare il tag href lo legge ma quando vado ad inserire l'immagine (<img src..>) non lo legge, o meglio legge solo il contenuto del campo del db immagine (miaimmagine.jpg) . Qualcuno può aiutarmi.
Per chi fosse interessato allo script completo posso inviare lo zip completo.
Grazie infinite
<script>
var oXmlHttp = null;
var iInterval = 10000;
var iLastCommentId = -1;
var divNotification = null;
function checkComments() {
if (!oXmlHttp) {
oXmlHttp = zXmlHttp.createRequest();
} else if (oXmlHttp.readyState != 0) {
oXmlHttp.abort();
}
oXmlHttp.open("get", "CheckComments.php", true);
oXmlHttp.onreadystatechange = function () {
if (oXmlHttp.readyState == 4) {
if (oXmlHttp.status == 200) {
var aData = oXmlHttp.responseText.split("||");
if (aData[0] != iLastCommentId) {
iLastCommentId = aData[0];
if (iLastCommentId != -1) {
showNotification(aData[1], aData[2]);
}
}
setTimeout(checkComments, iInterval);
}
}
};
oXmlHttp.send(null);
}
function showNotification(sName, sMessage) {
if (!divNotification) {
divNotification = document.createElement("div");
divNotification.className = "notification";
document.body.appendChild(divNotification);
}
divNotification.innerHTML = "New Comment
" + sName
+ " says: " + sMessage + "...
<a href=\"ViewComment.php?id="
+ iLastCommentId + "\">View</a>";
divNotification.style.top = document.body.scrollTop + "px";
divNotification.style.left = document.body.scrollLeft + "px";
divNotification.style.display = "block";
setTimeout(function () {
divNotification.style.display = "none";
}, 5000);
}
//if Ajax is enabled, assign event handlers and begin fetching
window.onload = function () {
if (zXmlHttp.isSupported()) {
checkComments();
}
};
</script>
....script php
<?php
header("Cache-control: No-Cache");
header("Pragma: No-Cache");
//database information
$sDBServer = "your.database.server";
$sDBName = "your_db_name";
$sDBUsername = "your_db_username";
$sDBPassword = "your_db_password";
//create the SQL query string
$sSQL = "select CommentId,Name,images LEFT(Message, 50) as ShortMessage from BlogComments order by Date desc limit 0,1";
$oLink = mysql_connect($sDBServer,$sDBUsername,$sDBPassword );
@mysql_select_db($sDBName) or die("-1|| || ");
if($oResult = mysql_query($sSQL) and mysql_num_rows($oResult) > 0) {
$aValues = mysql_fetch_array($oResult,MYSQL_ASSOC);
echo $aValues['CommentId']."||".$aValues['Name']."||".$aValues['ShortMessage'];
} else {
echo "-1|| || ";
}
mysql_free_result($oResult);
mysql_close($oLink);
?>