Hey guys, I'm having some AJAX troubles that hopefully someone can help me with. I have some PHP code, which works fine. And I'm trying to call the PHP function with AJAX. But I've never used AJAX at all so I'm a little confused. I've tried to fiddle around with some code but it's just not working. Wondered if anyone could help. The code is bellow:
PHP:
<?php
if($_GET['act'] == "generate_quotes") {
$db = mysql_connect("*", "*", "*") or die ("Unable to connect to database.");
mysql_select_db("quote") or die ("Unable to select database.");
$result = mysql_query( " SELECT * FROM `quote` ORDER BY RAND() LIMIT 0,1 " );
$fetch = mysql_fetch_array($result);
echo "<blockquote>".$fetch['q_quote']."</blockquote>";
mysql_close($db);
} else {
echo "<img src=\"1.png\">";
}
?>
The link which I want to call the function:
<div id="ajaxlink"><a href='gengen.php?act=generate_quotes'>Generate</a></div>
The AJAX:
function loadurl(dest) {
try {
("Microsoft.XMLHTTP");
} catch (e) {
}
xmlhttp.onreadystatechange = triggered;
xmlhttp.open("GET", dest);
xmlhttp.send("null");
}
function triggered() {
if ((xmlhttp.readyState == 4) (xmlhttp.status == 200)) {
document.getElementById("ajaxlink").innerHTML = xmlhttp.responseText;
}
}
The AJAX maybe completley wrong, I'm really not sure, but if so could somone show me how to go about doing this?
Thanks alot for any help :)