Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Could anyone let me know how to use a subdomain for ajax calls to a main domain?

I know it requires the use of CNAMES and whatnot, but I'm a bit clueless still. I want to make AJAX calls to ajax.samedomain.com, which in turn will reference to samedomain.com's data/scripts.

I also know that I somehow need to bypass the cross-domain security issue, and again I'm not sure on that either.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can not bypass same-origin policy security at all currently, in a browser neutral way, even if all the names point to the same place eventually. See http://en.wikipedia.org/wiki/Same_origin_policy for more info. You can get around it to some extent by using content loaded in via script files included in a page from the same domain in a hidden iframe, though this is not nearly as convenient as an AJAX request.

The DNS option you are thinking of is probably one of the DNS poisoning attacks, or something similar, that can be used to enable cross-domain scripting for nefarious purposes if certain security patches are not applied.

There is the HTML5 postMessage method which can be used to get script from different locations talking together, but not all common browsers support this yet so you are reducing your potential target audience if you rely on the feature.

share|improve this answer

Look into setting the document.domain property in javascript. I know I've used it to allow javascript updates between windows across child domains (x.company.com and y.company.com) before. May work fine for Ajax too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.