1

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.

2 Answers 2

1

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.

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .