Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

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 01-21-2009, 07:36 PM   PM User | #1
axm
New to the CF scene

 
Join Date: Oct 2007
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
axm is an unknown quantity at this point
Unhappy AJAX form submission with JQuery

Hello all, I'm pretty much a JS n00b and require some assistance with my JQuery form submission. As you will see from my code I'm doing the validation with PHP and PHP will show an error message or a success message upon submission. I wish to avoid the page load so I thought I'd use some AJAX. Please see below for my code:

http://clients.abstractx.co.uk/atom

Code:
<?php 
				if($added == "1") { echo "<h3>Thank you for subscribing!</h3>"; }
				else if($deleted == "1") { echo "<h3> " . $email . " Unsubscribed successfully</h3>"; }
				else if($error == "1") { echo "<h3>E&ndash;Mail address invalid</h3>"; }
				else if($notfound == "1") { echo "<h3>Sorry, E&ndash;Mail address not found</h3>"; }
				else if($error == "2") { echo "<h3>You've already subscribed!</h3>"; }
				else { echo "<h3>Simply enter your e&ndash;mail address below:</h3>"; } 
			?>
			<form id="emailform" action="add.php" method="post">
			<fieldset>
				<div><label>E&ndash;Mail</label></div><div><input id="email" type="text" name="email" class="text_box" /></div><div><input id="subscribe" type="submit" class="submit" name="subscribe" value="Subscribe" /></div><div><input id="unsubscribe" type="submit" class="submit" name="subscribe" value="Un-Subscribe" /></div>
			</fieldset>
			</form>
Code:
$(document).ready(function(){
	$("form#emailform").submit(function() {
 
	// we want to store the values from the form input box, then send via ajax below
	var email     = $('#email').attr('value');
 
		$.ajax({
			type: "POST",
			url: "add.php",
			data: "email=" + email,
			success: {
			}
		});
	return false;
	});
});
If you need to see my PHP then let me know.

Many thanks for your help!
axm is offline   Reply With Quote
Old 01-23-2009, 03:44 PM   PM User | #2
bgallegos
New Coder

 
Join Date: Jul 2008
Posts: 45
Thanks: 0
Thanked 6 Times in 6 Posts
bgallegos is an unknown quantity at this point
So what exactly is the problem that you are running into?
bgallegos 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 12:39 AM.


Advertisement
Log in to turn off these ads.