views:

45

answers:

1

I have grails server on http://mysite.com:8086/project/

ApiController renders some text(html code in my case) http://mysite.com:8086/project/api/lastorders

I have another server http://othersite.net/ - this is simple apache server with HTML page.

I want to show text returned from server on my page.

I've tried:

    <script type="text/javascript">
new Ajax.Request( "http://mysite.com:8086/project/api/lastorders", {
  method:  'get',
  onSuccess:  function(response){
    alert(response.responseText);
  },
  onFailure:  function(){
    alert('ERROR');
  }
});
    </script>

But response is empty...

+1  A: 

If you're trying to access http://mysite.com:8086/project/api/lastorders from http://othersite.net/, can't do that due to cross domain restrictions. If you want to get around that, the most common way is to set up http://othersite.net/ to proxy the request the server you're interested in getting data from and then return the result of that request. There are other solutions as well like using iframes, etc.

For more information, see http://www.w3.org/TR/XMLHttpRequest/ and search for "same origin" -- that's the policy that restricts you here.

Bialecki