I can't get the following simple ajax to work.
I don't get any error messages in FF error console
The div hides just like it's supposed to do onSuccess
The sql code never gets executed
index.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<title>Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="inc/prototype.js"></script>
<script type="text/javascript">
//<![CDATA[
Event.observe(window, 'load', function() {
var user = $('new_user');
if (user) {
user.href = "#";
user.setAttribute('onclick', "removeAlert('alert_new_user_home');");
}
});
function removeAlert(val) {
var url = 'inc/removeAlert.php';
new Ajax.Request(url, {
method: 'get',
parameters: { alert: val },
onSuccess: function() {
$(val).toggle();
},
onFailure: function() {
alert("There was an error with the connection");
}
});
}
//]]>
</script></head>
<body>
<div id="alert_new_user_home" class="info-alert">
<h2>My Alert</h2>
<div class="close-alert"><a id="new_user" href="?alert=alert_new_user_home">Delete This Alert</a></div>
</div>
</body>
</html>
inc/removeAlert.php
PHP Code:
<?php
$sql = "INSERT INTO `alerts` (`alert`, `user`)
VALUES ('".escape_string($_GET['alert'])."', 1)";
mysql_query($sql) or die();
?>