0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

As you're using Groovy under the covers, you make a proxy like this:

class SomeController {
   def someAction = {
      render(new URL(params.url).text())   
   }
}

and have your javascript call this controller/action

new Ajax.Request( "${createLink(controller: "some", action: "someAction", params: [url: "http://xxx.yy"])}", {
   method:  'get',
   onSuccess:  function(response){
     alert(response.responseText);
   },
   onFailure:  function(){
     alert('ERROR');
   }
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.