Forum: Ruby on Rails Issuing an ajax request to a different web server?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aeac27d9f81191536d3c86ee825d71b2?d=identicon&s=25 Don Mc (dmcclean)
on 2006-04-05 19:17
Is it possible to have an Ajax request go to a different server than
the one that originally rendered the web page? I am attempting this,
but the ajax server never gets the request.

For example, inside a form:

<%= submit_to_remote('add_lead','Add Lead(s)',
                          :url =>
"http://123.456.789.0:3000/users/add_lead",
                          :loading => 'item_loading()') %>


which generates the following html:

<input name="add_lead" onclick="new
Ajax.Request('http://123.456.789.0:3000/users/add_lead',
{asynchronous:true, evalScripts:true,
onLoading:function(request){item_loading()},
parameters:Form.serialize(this.form)}); return false;" type="button"
value="Add Lead(s)" />

Thanks,
Don
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-05 19:32
(Received via mailing list)
On Wed, Apr 05, 2006 at 07:17:18PM +0200, don mc wrote:
} Is it possible to have an Ajax request go to a different server than
} the one that originally rendered the web page? I am attempting this,
} but the ajax server never gets the request.
[...]

Browsers prevent this for very real security reasons. You cannot and
should
not even try to do that. If you really need to use a service at another
site, configure the main site to proxy to the other site.

} Thanks,
} Don
--Greg
Aeac27d9f81191536d3c86ee825d71b2?d=identicon&s=25 Don Mc (dmcclean)
on 2006-04-05 20:25
Gregory Seidman wrote:
> On Wed, Apr 05, 2006 at 07:17:18PM +0200, don mc wrote:
> } Is it possible to have an Ajax request go to a different server than
> } the one that originally rendered the web page? I am attempting this,
> } but the ajax server never gets the request.
> [...]
>
> Browsers prevent this for very real security reasons. You cannot and
> should
> not even try to do that. If you really need to use a service at another
> site, configure the main site to proxy to the other site.
>
> } Thanks,
> } Don
> --Greg

Greg,
  That makes sense. I will attempt to set up the proxy.

Thanks,
Don
B3260ee62969961010117e21e9872a3a?d=identicon&s=25 Kenneth Lee (Guest)
on 2006-04-05 22:05
(Received via mailing list)
You can't do it through XHR, but that doesn't mean you can't do AJAX.

There are quite a few things that do work across domains - image
references, posts to a hidden iframe, css links, and of course
<script> tags.  Just look at what advertisers have been doing for
quite a while and you'll get a pretty good idea for what is possible.
This topic is locked and can not be replied to.