Thursday, February 18, 2010

some jQuery for which I should be ashamed..

This beauty is for a wellness app that I'm working on (in Rails). What makes me proud (ashamed) is my use of 'var that = this'. I saw this somewhere..and couldn't help but laugh..and keep up the fun.

/* Click Event for Goal Completion */ $(".goal_link a").click(function(){ var that = this; $.ajax({ type: "PUT", url: $(this).attr("href"), data: "authenticity_token=#{form_authenticity_token}", success: function(msg){ $(that).parent().parent().parent().parent().parent().hide("slow"); }, error: function(req, status, error){ $("#user_goals_messages").html("We're sorry, but there was a problem updating this goal"); } }); return false; });

This bind event simply performs an ajax call (which would otherwise be sent normally) to mark a "Goal" complete. Upon success it is hidden.

No comments:

Post a Comment