Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-09-2009, 08:49 PM   PM User | #1
ryanhowdy
New to the CF scene

 
Join Date: Sep 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ryanhowdy is an unknown quantity at this point
Simple Ajax with Prototype

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();
?>
ryanhowdy is offline   Reply With Quote
Old 09-12-2009, 03:05 AM   PM User | #2
orca8767
New Coder

 
Join Date: Aug 2009
Posts: 84
Thanks: 1
Thanked 7 Times in 7 Posts
orca8767 can only hope to improve
From what you provided, it doesn't seem that you're initiating the DB connection...
http://us.php.net/manual/en/function.mysql-connect.php
http://us.php.net/manual/en/function.mysql-query.php
orca8767 is offline   Reply With Quote
Old 09-12-2009, 02:26 PM   PM User | #3
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
GET requests get cached, so if the values remain the same on the querystring the browser will not send a response to the server.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:38 PM.


Advertisement
Log in to turn off these ads.