The specific circumstances are:
I. Mutual access to the domain and subdomain: http://www.aa.com/and book.aa.com
Ii. Mutual access to this domain and other domains: http://www.aa.com/and http://www.bb.com/with IFRAME
Iii. Mutual access to this domain and other domains: http://www.aa.com/and http://www.bb.com/XMLHttpRequest Access Proxies
Iv. Mutual access to this domain and other domains: http://www.aa.com/and http://www.bb.com/Create dynamic scripts with JS
Today the main discussion of the 4th solution, this and the last difference is that the request is to use the <script> tag, this requirement is two domains are you to develop the line. The principle is JS file injection, in the domain within a to generate a JS tag, its SRC point to the request of another domain of a page b,b return data, you can directly return JS code. Because the SRC attribute of the script can be cross-domain.
Here we need to use the Jquery.getscript (URL, callback) method, the URL is the URL of the script file, the callback function is called after the script resource has been loaded and evaluated.
First create a JS file in bb.com, test.js
Copy Code code as follows:
var ojb = {msg: ' JS cross domain request succeeded '};
Then use $.getscript to load the Test.js script on the aa.com page
Copy Code code as follows:
$ (function () {
$.getscript (' Http://www.bb.com/test.js ', function () {
if (OJB) {
alert (obj.msg);
}
});
});
The greatest benefit of using the $.getscript function is the assurance that the callback function will be invoked after the script has finished loading.
Personally feel this method is simpler than using proxies and IFRAME.