View Single Post
Old 02-24-2008, 02:31 PM   #1 (permalink)
Gareth
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default AJAX - undefined?

Hi

I recently delved into the world of AJAX, but can't seem to get it working!

The actual displaying of a message in a div without loading is working; but there's something incorrect in my definition of fields.

I am using JQuery; with this javascript:

Code:
<script type="text/javascript">

	function request(){
	
		$.ajax({
		    type: "POST",
		    url: "insert2.php",
		    data: "username=" + $("#username").value,           
		    success: function(html){
		        $("#response").html(html);
		    }
		});
		
		}
	
	</script>
and then the form is thus:

Code:
				<form method="post" action="">

					<table class="formRegistration">
						<tr>
							<td>Username:</td>
							<td><input name="username" id="username" type="text" value="" maxlength="20" /></td>
						</tr>
						
						<tr>
							<td></td>
							<td><input type="button" name="submit" value="Insert" onclick="request()" /></td>

						</tr>
					</table>
				</form>
				
			<div id="response">
			<!-- Null-->
			</div>
insert2.php is simply:

PHP Code:
echo $_POST['username']; 
Whenever I press Insert, it comes up with just "undefined" in the response div.

A live version is running here:
SUI Mock Up

Any help would be greatly appreciated :)
Gareth is offline  
Reply With Quote