Gordon Yeong wrote in post #1020881: > Hello, 7stud, > I followed your recommendations and I managed to get good results. > > When I define the return data and then not put any "render" in the > controller action, it works. > > ------------------------------------ parts_controller.rb extract starts > ---------------------------------------- > # DELETE /parts/1 > # DELETE /parts/1.xml > def destroy > @part = Part.find(params[:id]) > @part.destroy > > respond_to do |format| > format.html { redirect_to(parts_url) } > format.xml { head :ok } > format.js { > @name = 'John Malko' > } > end > end > ------------------------------------ parts_controller.rb extract ends > ---------------------------------------- > > > ----------------------------------- application.js extract starts > --------------------- > $(document).ready(function () { > $('a[data-method="delete"]').live('ajax:success', > function(event, data, textStatus, jqXHR){ > alert(data.name + ' has been deleted'); > }); > }) > ----------------------------------- application.js extract ends > --------------------- >
Where does your the syntax for the event name 'ajax:success' come from? In prototype you can use the event name 'dom:loaded', although I can't find much information about where that name comes from either, but in any case that is prototype--not jQuery. > Questions: > ---------------- > > In my case (i'm not definining <action>.js.erb) as all I wanted was to > have > the deleted entries fade out (I defined some javascript in > application.js), > 1) for js format, can I safely assume that @name gets sent out in the > response as :json since the request was a xhr request? > No. json format has nothing in particular to do with ajax. > 2) When @name has been defined in the format.js block, can I assume that > the > data just gets sent in the response > No. Defining a variable and assigning it a value doesn't send anything to the browser. Instead, rails will attempt to render the page 'action_name.js.erb', and of course on that page any @ variables created in the action will be available. > and it is therefore up to any > javascript > to pick it up? > > Thank you -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.