Surya
2011-Aug-13 10:08 UTC
How to make an AJAX call to different domains in Ruby on Rails 3.0
I have an action email in my controller of application running on www.example.com and I am trying to send the form data of email to www.data.example.com/email where my another application receives the request and I am able to save the data in js format. But I want to send back the acknowledgement to www.example.com and replace the html using rjs template. Here are some code for you reference: *email.html.erb* called on *www.example.com* <div id="div_content"> <%= form_for(@user, :url => "http://data.example.com/mail", :remote => true) do |f| %> <%= f.label :email %> <%= f.text_field :email%> <% end %> </div> *email* action of application on : data.example.com/email - def email @user = User.create(params[:user]) respond_to do |format| if @user.save! format.html { redirect_to(user_page_path(@user.vip_id), :notice => ''Thank you! You are now on our priority list.'') } format.js else format.html { render :text => "user can not be saved at this moment!"} end end end *email.js.rjs* called on *www.data.example.com/email* page.replace_html :div_content, :partial => "show", :object => @user I can see in my log that request comes all the way from one domain to sub domain and even action gets triggered but, I can not get the response back to the main domain. So, is there any way to send a callback to main domain. I just want to reflect changes there at the form which is inside div_contentdiv and want to replace with content of _show.html.erb which I have on my sub domain. Many Thanks, Surya :) -- 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.
Walter Lee Davis
2011-Aug-13 12:59 UTC
Re: How to make an AJAX call to different domains in Ruby on Rails 3.0
On Aug 13, 2011, at 6:08 AM, Surya wrote:> I have an action email in my controller of application running on www.example.com > and I am trying to send the form data of email to www.data.example.com/email > where my another application receives the request and I am able to > save the data in js format. But I want to send back the > acknowledgement to www.example.com and replace the html using rjs > template. Here are some code for you reference: > > email.html.erb called on www.example.com > > <div id="div_content"> > > <%= form_for(@user, :url => "http://data.example.com/ > mail", :remote => true) do |f| %> > > > > <%= f.label :email %> > > <%= f.text_field :email%> > > <% end %> > </div> > > email action of application on : data.example.com/email - > > def email > @user = User.create(params[:user]) > > > > respond_to do |format| > if @user.save! > > format.html > { redirect_to(user_page_path(@user.vip_id), :notice => ''Thank you! > You are now on our priority list.'') } > > > > format.js > else > format.html { render :text => "user can not be saved at this > moment!"} > > > > end > end > end > email.js.rjs called on www.data.example.com/email > > page.replace_html :div_content, :partial => "show", :object => @user > > > > I can see in my log that request comes all the way from one domain > to sub domain and even action gets triggered but, I can not get the > response back to the main domain. So, is there any way to send a > callback to main domain. I just want to reflect changes there at the > form which is inside div_content div and want to replace with > content of _show.html.erb which I have on my sub domain. >If you''re trying to do all this in JavaScript, you''re going to run smack into the Same Origin Policy. Unless you use a proxy on www.example.com , you can''t update the page using data requested from data.example.com, or even www.example.com:2020 -- subdomain and port must match. More here: http://en.wikipedia.org/wiki/Same_origin_policy Walter -- 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.
Surya
2011-Aug-13 13:11 UTC
Re: How to make an AJAX call to different domains in Ruby on Rails 3.0
hey Thanks for your kind response. So, what I should do to achieve the same?? Any idea? On Sat, Aug 13, 2011 at 6:29 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org>wrote:> > On Aug 13, 2011, at 6:08 AM, Surya wrote: > > I have an action email in my controller of application running on >> www.example.com and I am trying to send the form data of email to >> www.data.example.com/email where my another application receives the >> request and I am able to save the data in js format. But I want to send back >> the acknowledgement to www.example.com and replace the html using rjs >> template. Here are some code for you reference: >> >> email.html.erb called on www.example.com >> >> <div id="div_content"> >> >> <%= form_for(@user, :url => "http://data.example.com/mail"**, :remote >> => true) do |f| %> >> >> >> >> <%= f.label :email %> >> >> <%= f.text_field :email%> >> >> <% end %> >> </div> >> >> email action of application on : data.example.com/email - >> >> def email >> @user = User.create(params[:user]) >> >> >> >> respond_to do |format| >> if @user.save! >> >> format.html { redirect_to(user_page_path(@**user.vip_id), :notice >> => ''Thank you! You are now on our priority list.'') } >> >> >> >> format.js >> else >> format.html { render :text => "user can not be saved at this >> moment!"} >> >> >> >> end >> end >> end >> email.js.rjs called on www.data.example.com/email >> >> page.replace_html :div_content, :partial => "show", :object => @user >> >> >> >> I can see in my log that request comes all the way from one domain to sub >> domain and even action gets triggered but, I can not get the response back >> to the main domain. So, is there any way to send a callback to main domain. >> I just want to reflect changes there at the form which is inside div_content >> div and want to replace with content of _show.html.erb which I have on my >> sub domain. >> >> > If you''re trying to do all this in JavaScript, you''re going to run smack > into the Same Origin Policy. Unless you use a proxy on www.example.com, > you can''t update the page using data requested from data.example.com, or > even www.example.com:2020 -- subdomain and port must match. More here: > http://en.wikipedia.org/wiki/**Same_origin_policy<http://en.wikipedia.org/wiki/Same_origin_policy> > > Walter > > -- > 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<rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at http://groups.google.com/** > group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en> > . > >-- Please consider the environment before printing this email. Regards, Surya -- 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.
Walter Lee Davis
2011-Aug-13 15:48 UTC
Re: How to make an AJAX call to different domains in Ruby on Rails 3.0
On Aug 13, 2011, at 9:11 AM, Surya wrote:> hey Thanks for your kind response. So, what I should do to achieve > the same?? Any idea?You can use a proxy endpoint on www.example.com to reflect what you get from data.example.com into the correct address space. You can also use a cross-domain privilege escalation to leave things as they are. If you control both servers, google "cross-domain JavaScript" for a thousand pounds of documentation on how to set this up. Personally, I would see if you could re-architect the system so that the request could happen within the same domain. You may be able to set up your server such that www.example.com/data/ and data.example.com/ are precisely the same thing. Walter> > On Sat, Aug 13, 2011 at 6:29 PM, Walter Lee Davis > <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > On Aug 13, 2011, at 6:08 AM, Surya wrote: > > I have an action email in my controller of application running on www.example.com > and I am trying to send the form data of email to www.data.example.com/email > where my another application receives the request and I am able to > save the data in js format. But I want to send back the > acknowledgement to www.example.com and replace the html using rjs > template. Here are some code for you reference: > > email.html.erb called on www.example.com > > <div id="div_content"> > > <%= form_for(@user, :url => "http://data.example.com/ > mail", :remote => true) do |f| %> > > > > <%= f.label :email %> > > <%= f.text_field :email%> > > <% end %> > </div> > > email action of application on : data.example.com/email - > > def email > @user = User.create(params[:user]) > > > > respond_to do |format| > if @user.save! > > format.html > { redirect_to(user_page_path(@user.vip_id), :notice => ''Thank you! > You are now on our priority list.'') } > > > > format.js > else > format.html { render :text => "user can not be saved at this > moment!"} > > > > end > end > end > email.js.rjs called on www.data.example.com/email > > page.replace_html :div_content, :partial => "show", :object => @user > > > > I can see in my log that request comes all the way from one domain > to sub domain and even action gets triggered but, I can not get the > response back to the main domain. So, is there any way to send a > callback to main domain. I just want to reflect changes there at the > form which is inside div_content div and want to replace with > content of _show.html.erb which I have on my sub domain. > > > If you''re trying to do all this in JavaScript, you''re going to run > smack into the Same Origin Policy. Unless you use a proxy on www.example.com > , you can''t update the page using data requested from > data.example.com, or even www.example.com:2020 -- subdomain and port > must match. More here: http://en.wikipedia.org/wiki/Same_origin_policy > > Walter > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . > > > > > -- > Please consider the environment before printing this email. > > > Regards, > Surya > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > .-- 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.