0

I want to make an AJAX call from www.mysite.com to api.mysite.com. Is this possible?

I've ready about document.domain, but as far as I can tell thats only good for cross DOM communication, such as through an iframe.

I'm also aware of CORS but am looking for a subdomain-specific solution, if there is one.

I looked at other questions before asking here and the only solutions I found were CORS (which I prefer not to use as the solutions I found for NGINx to do his were marked experimental) and proxies, which I don't want either for server load reasons.

Is there a way to do this?

Thanks

3
  • My first thought, without writing any code, is this should be possible since it is a sub-domain. Have you tried this and gotten errors? Commented Feb 28, 2012 at 14:01
  • See stackoverflow.com/a/7736250/27862 and stackoverflow.com/q/3076414/27862 Commented Feb 28, 2012 at 14:18
  • Sorry, I wasn't clear. I've updated the question: I looked at other questions before asking here and the only solutions I found were CORS (which I prefer not to use as the solutions I found for NGINx to do his were marked experimental) and proxies, which I don't want either for server load reasons. Commented Feb 28, 2012 at 14:29

1 Answer 1

0

Here is almost the same question. You have three options:

  1. iframe + document.domain (see link above for details)
  2. set up proxy to redirect all request from www.mysite.com/api to api.mysite.com (to avoid cross-domain (or subdomain) issue completely)
  3. use jsonp
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but I need another solution if possible. An iFraem is very messy and problematic, the proxy is a problem due to server load reasons and jsonp doesn't solve my need for POST.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.