Hello all, I''m trying to get (using Ajax) whatever URL the user clicks on the page. Also, I want to store the results from the URL request in a JS variable. Did somebody know helper in Rails which allow me to do that ? Thanks, Thib --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Well, I have found some interesting code : (http://prototypejs.org/learn/introduction-to-ajax) # new Ajax.Request(''/some_url'', { method:''get'', onSuccess: function(transport){ var response = transport.responseText || "no response text"; alert("Success! \n\n" + response); }, onFailure: function(){ alert(''Something went wrong...'') } }); ## But, instead of using ''/some_url'', I would like to use ''http:// a_different_domain.com..." According to the "Prototype" library website : "Ajax requests can only be made to URLs of the same protocol, host and port of the page containing the Ajax request" -> does somebody know if it''s only a "Prototype" library restriction, or if it''s a restriction for Ajax in general ? if it''s not, somebody have an idea to make it work ? Thanks Thib --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Not sure, but I think it''s a general restriction of XMLHTTPRequest in browsers in order to avoid security loopholes. It would be too easy if this were possible to have a user submit information to other websites without them knowing. Dirk. On 28 aug, 04:03, Thib21 <thibault.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, I have found some interesting code : > (http://prototypejs.org/learn/introduction-to-ajax) > > # > new Ajax.Request(''/some_url'', > { > method:''get'', > onSuccess: function(transport){ > var response = transport.responseText || "no response text"; > alert("Success! \n\n" + response); > }, > onFailure: function(){ alert(''Something went wrong...'') } > }); > ## > > But, instead of using ''/some_url'', I would like to use ''http:// > a_different_domain.com..." > > According to the "Prototype" library website : > "Ajax requests can only be made to URLs of the same protocol, host and > port of the page containing the Ajax request" > -> does somebody know if it''s only a "Prototype" library restriction, > or if it''s a restriction for Ajax in general ? if it''s not, somebody > have an idea to make it work ? > > Thanks > Thib--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
It is indeed a javascript security restriction for the reason mentioned below. The best solution is to submit the request to your server and have the server fetch the page and process it (send it back as a response). And usually it''s a good idea to cache those offsite fetched responses. On 29 Aug 2008, at 12:57, deegee wrote:> Not sure, but I think it''s a general restriction of XMLHTTPRequest in > browsers in order to avoid security loopholes. It would be too easy if > this were possible to have a user submit information to other websites > without them knowing. > > Dirk. > > On 28 aug, 04:03, Thib21 <thibault.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Well, I have found some interesting code : >> (http://prototypejs.org/learn/introduction-to-ajax) >> >> # >> new Ajax.Request(''/some_url'', >> { >> method:''get'', >> onSuccess: function(transport){ >> var response = transport.responseText || "no response text"; >> alert("Success! \n\n" + response); >> }, >> onFailure: function(){ alert(''Something went wrong...'') } >> }); >> ## >> >> But, instead of using ''/some_url'', I would like to use ''http:// >> a_different_domain.com..." >> >> According to the "Prototype" library website : >> "Ajax requests can only be made to URLs of the same protocol, host >> and >> port of the page containing the Ajax request" >> -> does somebody know if it''s only a "Prototype" library >> restriction, >> or if it''s a restriction for Ajax in general ? if it''s not, somebody >> have an idea to make it work ?Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---