dianikol85 Posted August 19, 2010 Report Share Posted August 19, 2010 Hi to all. I want your opinion about a jquery practice So here is the thing I have a database and one table lets call it test_table and it has three fields : id, lastName, firstName. In the index.php ilets say we create a table | id | First Name | Last name | +/- and three button: 1) Add new row 2) Save the row 3) Update the row So far so good. When i click the "Add new row" button via jquery we create a new row at the end of the table with 4 fields which contain a counter for the Id, two text inputs for the names and the last one contans two buttons the "Save the row" and the "Update the row". When the rows has been added i hide the "Update the row" button. So i fill the text inputs with data and then i click "Save the row" and with ajax i insert the data in the database. so when the insert action has completed i hide th e "Save the row" button and show the "Update the row" button. In order to do the update for this particular row when i did the insert i echo back the max id of the table and save it in a hidden input somewhere in the added row so i can access it with $(this). This process can be repeated for every new row when i click the Add button. What do you think about this technique. Do you suggest something more efficient than that? i would be very happy if you have a better solution although mine works very well i think. Thank you in advance and looking forward for your replies Quote Link to comment Share on other sites More sharing options...
dianikol85 Posted August 21, 2010 Author Report Share Posted August 21, 2010 Tell me if i didn't clear enough to explain more . My english aren't very well..... Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 21, 2010 Report Share Posted August 21, 2010 Sounds fine to me. You haven't provided any code, so I can't say if the code itself is any good, but if it works, it works. Quote Link to comment Share on other sites More sharing options...
dianikol85 Posted August 21, 2010 Author Report Share Posted August 21, 2010 ok i'll prepare an example and i will post it to see. Quote Link to comment Share on other sites More sharing options...
BeeDev Posted August 23, 2010 Report Share Posted August 23, 2010 - ID should be generated automatically by the database's "autonumber" field. You shouldn't need a counter for that. You only need ID's when updating a row. - Don't forget to attach a random string as a querystring to your AJAX url so the browser doesn't cache the result, and returns "Success" everytime even if there was an error. Also good practice to "Disable" any buttons during the AJAX submission to prevent any double-entries. - Think it would be nice to update the current table with newly added records once they've been inputted. Maybe another AJAX page that returns all records as "<table>" in html format, or just an array/json can do the job as well. Quote Link to comment Share on other sites More sharing options...
dianikol85 Posted August 24, 2010 Author Report Share Posted August 24, 2010 - ID should be generated automatically by the database's "autonumber" field. You shouldn't need a counter for that. You only need ID's when updating a row. - Don't forget to attach a random string as a querystring to your AJAX url so the browser doesn't cache the result, and returns "Success" everytime even if there was an error. Also good practice to "Disable" any buttons during the AJAX submission to prevent any double-entries. - Think it would be nice to update the current table with newly added records once they've been inputted. Maybe another AJAX page that returns all records as "<table>" in html format, or just an array/json can do the job as well. 1) I use the counter just to have an order to the table. No other reason. 2)Disabling the buttons during Ajax is a nice one. 3) All the insertions are instantly. So it feels like awindows app. Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.