Running an AJAX code on the submit of a form

Here's my form:\[code\]<form action="/scripts/addemail_fb.php" method="post"><input type="text" name="email" value="http://stackoverflow.com/questions/1977040/Enter your email here!" /><input id="submit" type="submit" name="submit" value="http://stackoverflow.com/questions/1977040/Go!" /></form>\[/code\]And my jQuery:\[code\] $(document).ready(function() { $('form').submit(function() { email = $('input[name=email]').val(); $.post("/scripts/addemail.php", {email_address:email}, function(data){ if(data =http://stackoverflow.com/questions/1977040/="invalid") { alert("invalid"); } else if(data =http://stackoverflow.com/questions/1977040/="used") { alert("used"); } else if(data =http://stackoverflow.com/questions/1977040/="success") { alert("success"); } else { alert("error"); } }); }); });\[/code\]and my PHP:\[code\]<?phpmysql_connect ('localhost', '********', '********') ;mysql_select_db ('Blog');function check_email($input) { $input = htmlspecialchars(strip_tags($input)); $checkaddress = "SELECT * FROM emails WHERE email='$input'"; $query = mysql_query($checkaddress); if (!eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $input)) { return "invalid"; } else if ( mysql_num_rows($query) >= 1 ) { return "used"; } else { $result = mysql_query("INSERT INTO emails (email) VALUES ('$input')"); return "success"; }}$email = urldecode(implode(file('php://input')));$result = check_email($email);echo $result;?>\[/code\]The problem is that its going to the action="/scripts/addemail_fb.php" instead of the jQuery. I'm new to AJAX, and AJAX with jQuery, but I've been using jQuery for quite some time. I think there are two problems: I don't think that the information is being sent to the jQuery correctly, and I'm not sure how to deal with the key:value pairs (email_address:email) in PHP. Thanks for any help! And yes, I'm obviously a beginner.
 
Top