Hey, I''m brand new to AJAX and scriptalicious, so i''m hoping for some help. inside hello.php I have this piece of code to grab and loop out users in the database: function test(){ $query = mysql_query(''SELECT * FROM `testing`''); while($i = mysql_fetch_row($query)) { echo''<div class="testie">''; echo $i[0] . "<br />"; echo $i[1] . "<br />"; echo $i[2] . "<br />"; echo ''<a href="javascript: MyAjaxRequest(\''main\'',\''hello.php? ID='' . $i[2] .''\'')">Delete</a><br />''; echo ''</div>''; } } This piece of code deletes the user from the database if chosen, and then re-generates the list via AJAX: if($_GET[ID] == "") { echo "nothing"; }else{ $delete = mysql_query(''DELETE FROM `testing` WHERE ID = '' . $_GET[ID] . ''''); echo "Item has been deleted"; test(); } Now comes the problem, how would i make the delete div use the scriptalcious fade effect to fade out, then execute the AJAX function to delete the user? Any help is greatly appreciated! Thanks, envex --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I won''t critique your PHP, but most all asynchronous scriptaculous or prototype calls have a set of callback hooks. You''ll need to look in the documentation for the specifics since the naming isn''t consistent, but for example you could do: new Effect.Appear(element, { afterFinish: function(el) { // This is executed after the effect has done its stuff } }); See http://wiki.script.aculo.us/scriptaculous/show/CoreEffects for more. Similarly you could do the Ajax stuff first and use the onComplete or onSuccess callbacks to then invoke the effect. On 5/17/07, envex <ecksys-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey, > > I''m brand new to AJAX and scriptalicious, so i''m hoping for some help. > > inside hello.php > > I have this piece of code to grab and loop out users in the database: > > function test(){ > $query = mysql_query(''SELECT * FROM `testing`''); > > while($i = mysql_fetch_row($query)) > { > echo''<div class="testie">''; > echo $i[0] . "<br />"; > echo $i[1] . "<br />"; > echo $i[2] . "<br />"; > echo ''<a href="javascript: MyAjaxRequest(\''main\'',\''hello.php? > ID='' . $i[2] .''\'')">Delete</a><br />''; > echo ''</div>''; > } > } > > This piece of code deletes the user from the database if chosen, and > then re-generates the list via AJAX: > > if($_GET[ID] == "") > { > echo "nothing"; > }else{ > $delete = mysql_query(''DELETE FROM `testing` WHERE ID = '' . > $_GET[ID] . ''''); > echo "Item has been deleted"; > test(); > } > > Now comes the problem, how would i make the delete div use the > scriptalcious fade effect to fade out, then execute the AJAX function > to delete the user? > > Any help is greatly appreciated! > > Thanks, > > envex > > > > >-- Jesse E.I. Farmer e: jesse-h8Qh2m8E5SHQT0dZR+AlfA@public.gmane.org w: http://20bits.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I hope the SQL you''ve posted is not like the code in your program. You have a serious SQL injection problem. For example, what if $_GET [''ID''] === ''1 OR true''? Some sample Fade effects can be found here: http://wiki.script.aculo.us/scriptaculous/show/Effect.Fade Effects allow you to include callbacks. You might find "afterFinish" to be the most useful. See more about effect callbacks here: http://wiki.script.aculo.us/scriptaculous/show/CoreEffects Instructions for doing an AJAX request are here: http://prototypejs.org/api/ajax/request ... although you may want to refactor a bit and look into the Ajax.Updater. http://prototypejs.org/api/ajax/updater If you want to fade, you''ll need to add ids to each list item, or find some other way of passing the element reference to your function. Wrap it all together, and your final code might look something like this (untested, etc.) Effect.Fade(''id_of_list_element'', {afterFinish: function() { //Do ajax call here new Ajax.Updater(''id_of_list_master_container'', ''hello.php'', { parameters: ''ID=''+id_of_element; }); } }); You''d have to somehow tie this behavior to each item. This would be easier to do if you used list items instead of line breaks. On the subject of refactoring, why repopulate the entire list if you''re only removing an item? Why not just remove the item (w/ Effect.Fade), and be done with it? Sounds like you''re creating extra work for yourself. TAG On May 17, 2007, at 1:46 PM, envex wrote:> > Hey, > > I''m brand new to AJAX and scriptalicious, so i''m hoping for some help. > > inside hello.php > > I have this piece of code to grab and loop out users in the database: > > function test(){ > $query = mysql_query(''SELECT * FROM `testing`''); > > while($i = mysql_fetch_row($query)) > { > echo''<div class="testie">''; > echo $i[0] . "<br />"; > echo $i[1] . "<br />"; > echo $i[2] . "<br />"; > echo ''<a href="javascript: MyAjaxRequest(\''main\'', > \''hello.php? > ID='' . $i[2] .''\'')">Delete</a><br />''; > echo ''</div>''; > } > } > > This piece of code deletes the user from the database if chosen, and > then re-generates the list via AJAX: > > if($_GET[ID] == "") > { > echo "nothing"; > }else{ > $delete = mysql_query(''DELETE FROM `testing` WHERE ID = '' . > $_GET[ID] . ''''); > echo "Item has been deleted"; > test(); > } > > Now comes the problem, how would i make the delete div use the > scriptalcious fade effect to fade out, then execute the AJAX function > to delete the user? > > Any help is greatly appreciated! > > Thanks, > > envex > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Thursday 17 May 2007 20:59, Jesse Farmer wrote:> Similarly you could do the Ajax stuff first and use the onComplete or > onSuccess callbacks to then invoke the effect. >I''d strongly advise this. If you delete the element locally, and then send a request back to the server to delete from the DB, you run the risk of the request failing, and your UI getting out of synch. To rephrase Tom Gregory''s example solution to call the Ajax first (also untested etc.): new Ajax.Updater( ''id_of_list_master_container'', ''hello.php'', { parameters: ''ID=''+id_of_element, onComplete:function(response){ var deletables=document.getElementsByClassName (''deleteMe'',''id_of_list_master_container''); deletables.each( function(item){ new Effect.Fade(item); } ); } } This is assuming that your hello.php script will return a HTML list of all items in the list, including the ones you''ve just deleted, and mark the deleted ones with a CSS class ''deleteMe''. document.getElementsByClassName() then finds each of these elements within the container, and applies a Fade effect to each of them. If refreshing the list has a possibility of adding new items in as well, then you could mark them with a CSS class too, and apply an Effect.Appear() or whatever to add an extra bit of bling - I mean helpful user notification. :-) HTH Dave -- ---------------------- Author Ajax in Action http://manning.com/crane Ajax in Practice http://manning.com/crane2 Prototype & Scriptaculous in Action http://manning.com/crane3 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Michael, I think we''re agreeing with each other? Delete at the DB, then delete locally when that''s been confirmed, right? (And if the confirmation doesn''t come back, do all those error-condition things that we omit from these sorts of examples.) Cheers, Dave On Friday 18 May 2007 14:18, Michael Peters wrote:> Dave Crane wrote: > > On Thursday 17 May 2007 20:59, Jesse Farmer wrote: > >> Similarly you could do the Ajax stuff first and use the onComplete or > >> onSuccess callbacks to then invoke the effect. > > > > I''d strongly advise this. If you delete the element locally, and then > > send a request back to the server to delete from the DB, you run the risk > > of the request failing, and your UI getting out of synch. > > No, his advice is still valid, you just need to switch your steps. Send the > request to delete it and when you get the response back and everything''s > good, then you delete it locally.-- ---------------------- Author Ajax in Action http://manning.com/crane Ajax in Practice http://manning.com/crane2 Prototype & Scriptaculous in Action http://manning.com/crane3 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Dave Crane wrote:> On Thursday 17 May 2007 20:59, Jesse Farmer wrote: >> Similarly you could do the Ajax stuff first and use the onComplete or >> onSuccess callbacks to then invoke the effect. >> > I''d strongly advise this. If you delete the element locally, and then send a > request back to the server to delete from the DB, you run the risk of the > request failing, and your UI getting out of synch.No, his advice is still valid, you just need to switch your steps. Send the request to delete it and when you get the response back and everything''s good, then you delete it locally. -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- Unable to lauch php-script to truncate database
- Scriptalicious: Ajax Inline Text Editor
- R Tools & Vista_x64: Problem compiling RMySQL?
- Sortable list (scriptalicious) and updating database
- ** PLEASE HELP A NEWBIE ** Status: 500 Internal Server Error no such file to load -- mysql