rails 3 ajax response from another application
I have a bug tracking application which is to开发者_Python百科 be used for multiple applications.
In the application I have a tickets_controller
thats renders a new form in the facebox using facebox_render
.
This is working fine when I do this in the same application.
To make it clear say, bug tracker is running on localhost:3000
and client application is running on localhost:3001
But if I hit localhost:3000/tickets/new
from localhost:3001
via an ajax request. It doesn't loads the form at all. I tried putting a div
in localhost:3001
app and updating it via localhost:3000/tickets/new
, doesn't works either.
Is there anything I need to configure or need to add?
This is due to the limitations of the XMLHttpRequest and its same origin policy. Simply put, you just can't do cross-site requests via AJAX (which is your case since port number is a part of the definition of the origin).
There are couple of workarounds to this problem that you may want to investigate, eg. JSONP or proxy web service. This article sums up couple of possible solutions quite nicely.
From the Facebox example, it looks like it loads remote page content via XHR/AJAX. You can only do this with pages on the same domain/port.
In your scenario, you would need to load the page into an iFrame. I don't know if Facebox can do that. Check out Fancybox as it can do this and is easy to implement.
精彩评论