Search code examples
ajaxxmlhttprequestcross-domainsproutcore

Cross Domain request for service using SproutCore


I have been trying to get this resolved, without any success.

I have a webapp residing on my domain, say www.myDomain.com. I need to call a service which is present on another domain, say www.anotherDomain.com/service.do?

I'm using SproutCore's SC.Request.getUrl(www.anotherDomain.com/service.do?) to call that service.

I get an error that says, Origin www.myDomain.com is not allowed by access-control-allow-origin.

When I was in dev stages, and using sc-server, the issue was resolved using proxies. Now that I have deployed the app to an actual server, I replaced all the lines where I had set up the proxy with the actual domain name. I have started getting that error again.

The problem is that I CANNOT MAKE ANY CHANGES to the server on the other domain. All the posts that I have come across state that the other server on the other domain ought to provide access-control-allow-origin header and that it ought to support the OPTIONS verb.

My question is, is it possible for me to connect to that service using SproutCore's SC.Request.getUrl() method?

Additionally, the other posts that I have read mentioned that a simple GET request ought not to be preflighted. Why then are my requests going as OPTION instead of GET?

Thanks a ton in advance! :D


Solution

  • This is not a Sproutcore issue; it's a javascript Same Origin Policy issue.

    If you can't modify the production server, you have no option but to develop your own proxy server, and have your proxy hit the real service.

    This is effectively replacing sc-server in your production environment.

    All this server would do is take the incoming request and pass it along to www.anotherDomain.com/?service.do.

    You would need to make sure you passed all parameters, cookies, headers, the http verb, etc....

    This is far from ideal, because now errors can occur in more places. Did the real service fail? Did the proxy fail? etc.

    If you could modify the other domain, you could

    1) deploy your SC app there.
    2) put in the CORS headers so you could make cross domain requests