Dojo 1.8.7 cross domain XHR test
HTML
<style>
.main textarea {
font-size: 9pt;
}
h3 {
padding: 0;
margin: 0;
}
</style>
<div class="main">
<div>
This page <em>should</em> demonstrate use of <code>window.XDomainRequest</code> use on IE, but it doesn't seem to work on CWD3 as <code>window.XDomainRequest</code> seems to be <code>undefined</code>.
<br><a href="http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx">http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx</a>
<br><a href="http://stackoverflow.com/a/14606197">http://stackoverflow.com/a/14606197</a>
</div>
<h3>Log</h3>
<textarea id="log" style="width: 100%" rows="8"></textarea>
<h3>xhr-content</h3>
<textarea id="xhr-content" style="width: 100%" rows="8"></textarea>
<h3>xdr-content</h3>
<textarea id="xdr-content" style="width: 100%" rows="8"></textarea>
</div>
JavaScript
// http://stackoverflow.com/a/14606197
require(["dojo/Deferred", "dojo/request/xhr"], function (Deferred, xhr) {
var log = function (value) {
var el = document.getElementById("log");
el.value += (typeof value) + ": " + value + "\n";
};
var err = function (value) {
if ("string" !== typeof value) {
var s = "";
for (var i in value) {
s += (i + "=" + value[i]);
}
value = s;
}
log("ERR: " + value);
};
var setContent = function (id, value) {
var el = document.getElementById(id);
el.value = value;
}
function xdr(url, options) {
var def = new Deferred();
if ("undefined" === typeof XDomainRequest) {
def.reject("XDomainRequest is undefined");
return def;
}
var xdr = new XDomainRequest();
xdr.onload = function (e) {
def.resolve(xdr.responseText);
}
options.method = options.method || "GET";
xdr.open(options.method, url);
xdr.send();
return def;
}
log("typeof window.XDomainRequest = " + (typeof window.XDomainRequest));
var url = "http://updates.html5rocks.com/";
var options = {
method: "GET",
headers: {
"X-Requested-With": ""
}
};
xhr(url, options).then(function (data) {
setContent("xhr-content", data);
}, err);
xdr(url, options).then(function (data) {
setContent("xdr-content", data);
}, err);
});