Jump to content

jQuery - After adding to the database display new record via div/Ajax


suttercain

Recommended Posts

Hi everyone,

 

I hame a basic web application which uses jQuery to add a first name and last name to a MySQL database via AJAX. This part works. But what I would like to happen after they click submit and the data is added; is for a div to output the records, via ajax, from the database table so they can see the new record.

 

So they add their name and last name to the form, click submit, it's added to the database via AJAX (this part works, then below the form in a div the new record would display. The last part has got me stuck.

 

<script src="js/jquery-1.2.6.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("form#submit").submit(function() {
// we want to store the values from the form input box, then send via ajax below
var fname     = $('#fname').attr('value');
var lname     = $('#lname').attr('value');
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "fname="+ fname +"& lname="+ lname,
		success: function(){
			/*$(function(){$('div.success').fadeIn();});*/ <--Works for static content
			$('div.success').load("echo.php"); <--thought this would work, doesn't...
		}
	});
return false;
});
});

</script>

//THE FORM & DIV WHERE I WOULD LIKE THE NEW RECORD(S) TO DISPLAY

<div class="container">
<form id="submit" method="post">
	<fieldset>
		<legend>Enter Information</legend>
		<label for="fname">Client First Name:</label>
		<input id="fname" class="text" name="fname" size="20" type="text">
		<label for="lname">Client Last Name:</label>
		<input id="lname" class="text" name="lname" size="20" type="text">

		<button class="button positive"><img src="images/butup.gif" alt=""></button>
	</fieldset>
</form>
</div>
<div class="success" style="display: none;">sd</div>

 

I thought the load after a success was returned would work, but no luck. Any ideas?

 

Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.