Si ho letto ed infatti ho inserito questo nella mia pagina!
Codice PHP:
<script type="text/javascript" language="Javascript">
function createXMLHttpRequest() {
var ua;
if(window.XMLHttpRequest) {
try {
ua = new XMLHttpRequest();
}
catch(e) {
ua = false;
}
}
else if(window.ActiveXObject) {
try {
ua = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
ua = false;
}
}
return ua;
}
var req = createXMLHttpRequest();
function sendRequest(id) {
req.open('get', '?option=oroscopo&segno=' + id, true);
req.onreadystatechange = handleResponse;
req.send(null);
}
function handleResponse() {
if(req.readyState == 4) {
var response = req.responseText;
alert(req.responseText);
}
}
</script>
Ho capito che la risposta sarà nella funzione handleResponse() ma vorrei capire come inglobare codice php nel js
Codice PHP:
$segno = mysql_escape_string($_GET['segno']);
$query = "SELECT * FROM table_oroscopo_segni a, table_oroscopo b WHERE a.nome = b.segno AND b.segno = '$segno' AND b.mese = 'ottobre' AND b.anno = '".date("Y")."' AND b.approvato = 1";
$result = mysql_query($query,$GLOBALS['db']);
if(mysql_num_rows($result) == 1)
{
$row = mysql_fetch_array($result);
$immagine = $row['immagine'];
$segno = ucfirst($row['nome']);
$elemento = ucfirst($row['elemento']);
$qualita = ucfirst($row['qualita']);
$pianeta = ucfirst($row['pianeta']);
$colore = ucfirst($row['colore']);
$pietra = ucfirst($row['pietra']);
$testo = $row['testo'];
}
Questa è la parte che preleva dati dal db e li inserisce in alcune variabili che richiamerò nella pagina!
Ora in pratica vorrei fondere questi due snippets, per far si che ajax faccia la sua parte!