Avicinnian
Avicinnian

Reputation: 1830

Clarification of cross-domain AJAX?

I'd like to get some clarification on what cross-domain AJAX means in terms of the mechanics behind it.

Say for example, I have a website http://www.example.com. This website contains a javascript file, which within contains several standard jQuery based AJAX calls (e.g. $.post(), $.get() etc), located at http://www.example.com/js/script.js.

Now, I have another website http://www.helloworld.com, which contains the following;

<script type="text/javascript" src="http://www.example.com/js/script.js"></script>

Would the AJAX requests within http://www.example.com/js/script.js which make requests to http://www.example.com be considered "cross-domain" and therefore carry compatibility issues when the file is included on http://www.internet.com?

Any answers would be great!

Upvotes: 0

Views: 206

Answers (2)

Ghigo
Ghigo

Reputation: 1697

In order to be able to include a javascript from another domain, the sever that serves that JS need to provide the file with the correct headers. In particular the headers need to have the Access-Control-Allow-Origin set for the domain requiring a cross-domain JS.

Just for test purpose you might want to run Chrome with the parameter --allow-file-access-from-files and it won't stop cross origin requests.

Upvotes: 1

SeanCannon
SeanCannon

Reputation: 77996

JS is executed on the client side, so it doesn't matter where the source of the file resides, it'll be executed from the domain in the address bar.

Upvotes: 3

Related Questions