Dojo 1.8.7 cross domain dojo/text test
HTML
<script>
dojoConfig = {
textPluginHeaders: {"X-Requested-With": null},
map: {
"*": {"dojo/request/xhr": "myxhr"}
}
};
</script>
<script data-dojo-config="async: 1"
src="//ajax.googleapis.com/ajax/libs/dojo/1.8.7/dojo/dojo.js"></script>
JavaScript
define("myxhr", [
'dojo/errors/RequestError',
'dojo/request/watch',
'dojo/request/handlers',
'dojo/request/util',
'dojo/has'/*=====,
'dojo/request',
'dojo/_base/declare' =====*/
], function(RequestError, watch, handlers, util, has/*=====, request, declare =====*/){
has.add('native-xhr', function(){
// if true, the environment has a native XHR implementation
return typeof XMLHttpRequest !== 'undefined';
});
has.add('dojo-force-activex-xhr', function(){
return has('activex') && !document.addEventListener && window.location.protocol === 'file:';
});
has.add('native-xhr2', function(){
if(!has('native-xhr')){ return; }
var x = new XMLHttpRequest();
return typeof x['addEventListener'] !== 'undefined' &&
(typeof opera === 'undefined' || typeof x['upload'] !== 'undefined');
});
has.add('native-formdata', function(){
// if true, the environment has a native FormData implementation
return typeof FormData === 'function';
});
function handleResponse(response, error){
var _xhr = response.xhr;
response.status = response.xhr.status;
response.text = _xhr.responseText;
if(response.options.handleAs === 'xml'){
response.data = _xhr.responseXML;
}
if(!error){
try{
handlers(response);
}catch(e){
error = e;
}
}
if(error){
this.reject(error);
}else if(util.checkStatus(_xhr.status)){
this.resolve(response);
}else{
error = new RequestError('Unable to load ' + response.url + ' status: ' + _xhr.status, response);
this.reject(error);
}
}
var isValid, isReady, addListeners, cancel;
if(has('native-xhr2')){
// Any platform with XHR2 will only use the watch mechanism for timeout.
isValid = function(response){
// summary:
// Check to see if the request should be taken out of the watch queue
return !this.isFulfilled();
};
cancel = function(dfd, response){
// summary:
// Canceler for deferred
response.xhr.abort();
};
addListeners = function(_xhr, dfd,...