Helpers in rails to get URL using AJAX

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

Well, I have found some interesting code :
(Prototype JavaScript Framework | 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

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.

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:

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