You can use JSONP to exchange different domains, regardless of settings and cross-domain access policies.
However, JSONP requires the server side to create a callback function with the returned data as a parameter.
I would suggest downloading simple Javascript content from a server that has the same cross-domain independence and security as a JSON request.
Say you have a Javascript file, data.js , in content.example.com or a service that returns the same content as the file in the response, with a JSON object with a variable prefix:
result = { "string1": "text1", "object1": { "string2": "text2", "number1": 5.6 }, "number2": 7, "array1": ["text3", "text4"] }
Then on your web page at www.example.com you can have a script with a loadJS function that loads the server response as a script:
var loadJS = function (url, callback) { var script = document.createElement('script'); script.type = "text/javascript"; script.src = url; script.onload = function (ev) { callback(window.result); delete window.result; this.parentNode.removeChild(this); }; document.body.appendChild(script); }; window.onload = function () { loadJS('http://content.example.com/data.js', function (data) { console.log(data); }); };
You can use this function in content.example.com for queries in the opposite direction.
To set cookies or perform any other functions available in JS, the response from script, data.js may contain a function, not a JSON object:
result = (function () { document.cookie = "cookie1=Value1; cookie2=Value2;"; return true; })();