Could someone please demonstrate the code to send both json (or xml) AND javascript (to be executed) in a single Ajax request? Is this even possible? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 8, 3:00 pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Could someone please demonstrate the code to send both json (or xml) AND > javascript (to be executed) in a single Ajax request? >Assuming you mean sending that as the response to an ajax request .... If you set the X-JSON header to be a json fragment Prototype (don''t know about other libraries) will deserialize that for you, and then the response body can be whatever you want. Personally if I''ve already written stuff to take a JSON response and do stuff based on that data, I wouldn''t want to also send back javascript fragments - I''d just write the client side code to do the desired action if the appropriate content was in the response JSON Fred> Is this even possible? > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jun 8, 3:00�pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Could someone please demonstrate the code to send both json (or xml) AND >> javascript (to be executed) in a single Ajax request? >> > > Assuming you mean sending that as the response to an ajax request .... > > If you set the X-JSON header to be a json fragment Prototype (don''t > know about other libraries) will deserialize that for you, and then > the response body can be whatever you want.Fred: Ok ... lets say I have two variables ABC and XYZ and I want to send the values of those two variables back to my jQuery code ... What''s the magic invocation to do that in Rails? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 8, 3:56 pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Jun 8, 3:00 pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Fred: > > Ok ... lets say I have two variables ABC and XYZ and I want to send the > values of those two variables back to my jQuery code ... > > What''s the magic invocation to do that in Rails?I''d just write render :json => {:abc => 1, :xyz => 2}.if you want to do it via a header because something else is in the body then call to_json yourself to get the json data and stick it in a header. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jun 8, 3:56�pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Frederick Cheung wrote: >> > On Jun 8, 3:00 pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> Fred: >> >> Ok ... lets say I have two variables ABC and XYZ and I want to send the >> values of those two variables back to my jQuery code ... >> >> What''s the magic invocation to do that in Rails? > > I''d just write render :json => {:abc => 1, :xyz => 2}.if you want to > do it via a header because something else is in the body then call > to_json yourself to get the json data and stick it in a header. > > FredFred (or anyone): Do you know of any tutorial that explains this header stuff? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 8, 4:51 pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > Do you know of any tutorial that explains this header stuff?Setting headers is pretty easy: response.headers[''X-JSON''] = blah.to_json And then in your client side code look at the the header and read the JSON (prototype will do this for you, jquery might not) Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jun 8, 4:51�pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> >> Do you know of any tutorial that explains this header stuff? > > Setting headers is pretty easy: > > response.headers[''X-JSON''] = blah.to_json > > And then in your client side code look at the the header and read the > JSON (prototype will do this for you, jquery might not) > > FredFred and all: Thank you, Fred. What is all this header and body stuff? I''d really like to understand this. Is there an overview? I have Googled stuff but ... I''m not finding any meat. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Jun 8, 2010 at 12:51 PM, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> What is all this header and body stuff? I''d really like to understand > this.Start with: http://www.w3.org/Protocols/rfc2616/rfc2616.html -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 8 June 2010 21:06, Hassan Schroeder <hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Jun 8, 2010 at 12:51 PM, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> What is all this header and body stuff? I''d really like to understand >> this. > > Start with: http://www.w3.org/Protocols/rfc2616/rfc2616.htmlI think that may be a bit heavy for starters. Possibly http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol is a bit more readable. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- Mongrel, .htaccess, cpanel, rewrite, Mongrel::HttpParserError
- rjs error TypeError: element.getElementsByTagName is not a function in rails 3+jquery
- ActiveRecord::AssociationTypeMismatch in UsersController#update
- Cmd line interface for ruby on rails app
- JSON::ParserError in controller