suttercain Posted June 28, 2010 Share Posted June 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206102-jquery-after-adding-to-the-database-display-new-record-via-divajax/ Share on other sites More sharing options...
trq Posted June 28, 2010 Share Posted June 28, 2010 What is within echo.php? Quote Link to comment https://forums.phpfreaks.com/topic/206102-jquery-after-adding-to-the-database-display-new-record-via-divajax/#findComment-1078488 Share on other sites More sharing options...
suttercain Posted June 30, 2010 Author Share Posted June 30, 2010 Right now it's simply echo "Hello!"; But I will change this to a mysql SELECT query and display the inputs of the most recent record to reflect the form inputs. Quote Link to comment https://forums.phpfreaks.com/topic/206102-jquery-after-adding-to-the-database-display-new-record-via-divajax/#findComment-1079239 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 I think the load() method would actually require a complete url so as to have the server execute the php. Quote Link to comment https://forums.phpfreaks.com/topic/206102-jquery-after-adding-to-the-database-display-new-record-via-divajax/#findComment-1079414 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.