# Issuing an ajax request to a different web server?

**URL:** <https://www.ruby-forum.com/t/issuing-an-ajax-request-to-a-different-web-server/56910>\
**Category:** Rails\
**Created:** [April 5, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/issuing-an-ajax-request-to-a-different-web-server/56910 "2006-04-05T19:17:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [April 5, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/issuing-an-ajax-request-to-a-different-web-server/56910/1 "2006-04-05T19:17:18Z")

</div>

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](http://123.456.789.0:3000/users/add_lead)”,  
:loading =\> ‘item\_loading()’) %\>

which generates the following html:

Thanks,  
Don

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [April 5, 2006, 7:32pm UTC](https://www.ruby-forum.com/t/issuing-an-ajax-request-to-a-different-web-server/56910/2 "2006-04-05T19:32:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [April 5, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/issuing-an-ajax-request-to-a-different-web-server/56910/3 "2006-04-05T20:25:31Z")

</div>

Gregory S. 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

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [April 5, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/issuing-an-ajax-request-to-a-different-web-server/56910/4 "2006-04-05T22:05:21Z")

</div>

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

 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.
