jQuery/AJAX

liryk

New Member
I would like to be able to star/un-star any given conversation (like Gmail for example.) When I click the "empty" star to mark something as important, I need to submit some ajax and then toggle to the star image. And visa versa, when I click a starred conversation, I need the ajax to submit and upon its success, then have "empty" star toggled back. Some HTML (in a nutshell):\[code\] <div class='__conversation'> <div class='__conversation_star'> <img class='__star_n' src='http://stackoverflow.com/questions/14533678/p_star_n.png'/> <img class='__star_y' src='http://stackoverflow.com/questions/14533678/p_star_y.png'/> </div> </div>\[/code\]And something with similar functionality to a basic:\[code\] $(".__conversation_star").click(function() { $(this).find('img').toggle(); });\[/code\]Some ajax:\[code\] $(".__conversation_star").click(function() { jQuery.ajax({ type: 'POST', url: "./process.conversation.php, data: {method: 'star'}, cache: true, success: function() { // Toggle to un-starred .__star_n } }); }); $(".__conversation_star").click(function() { jQuery.ajax({ type: 'POST', url: "./process.conversation.php", data: {method: 'star'}, cache: true, success: function() { // Toggle to starred .__star_n } }); });\[/code\]Is there a way I can perform a toggle upon success of the ajax? and/or what other methods of doing this are there that will work better?Thank you!
 
Back
Top