跨域问题我没处理过,做过的项目中也没有涉及到.感觉跨域问题是个比较烦的问题.浏览器的兼容性没办法保证.所以我们公司在开发中尽量避免需要跨域的情况.而是将常用的东西组件化,就像各种JS插件一样,js文件,css,资源都放在一起,重用时直接平移过去
不支持
看一下这个怎么解决跨域上传
需要自己修改,前后端都需要修改
domUtils.on(input, 'change', function(){
if(!input.value) return;
var loadingId = 'loading_' + (+new Date()).toString(36);
var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
var imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));
var allowFiles = me.getOpt('imageAllowFiles');
me.focus();
me.execCommand('inserthtml', '');
function showErrorLoader(title){
if(loadingId) {
var loader = me.document.getElementById(loadingId);
loader && domUtils.remove(loader);
me.fireEvent('showmessage', {
'id': loadingId,
'content': title,
'type': 'error',
'timeout': 4000
});
}
}
/* 判断后端配置是否没有加载成功 */
if (!me.getOpt('imageActionName')) {
errorHandler(me.getLang('autoupload.errorLoadConfig'));
return;
}
// 判断文件格式是否错误
var filename = input.value,
fileext = filename ? filename.substr(filename.lastIndexOf('.')):'';
if (!fileext || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
showErrorLoader(me.getLang('simpleupload.exceedTypeError'));
return;
}
var fd = new FormData();
fd.append("fileToUpload", input.files[0]);
var xhr = false;
try {
xhr = new XMLHttpRequest();// 创建 XMLHttpRequest对象,IE可能不行
} catch(e) {
xhr = ActiveXobject("Msxml12.XMLHTTP");// FOR IE
}
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var responseText = xhr.responseText;
json = (new Function("return " + responseText))();
console.log(json);
try {// "http://static.01event.com/fileupload"
link = me.options.imageUrlPrefix + json.filesDetail[0].savePath;
if (json.success && json.filesDetail[0].savePath) {
loader = me.document.getElementById(loadingId);
loader.setAttribute('src', link);
loader.setAttribute('_src', link);
loader.setAttribute('title', json.filesDetail[0].saveFile || '');
loader.setAttribute('alt', json.filesDetail[0].uploadName || '');
loader.removeAttribute('id');
domUtils.removeClasses(loader, 'loadingclass');
} else {
showErrorLoader && showErrorLoader(json.failReason);
}
} catch(e) {
link = me.options.imageUrlPrefix + json.url;
if(json.state == 'SUCCESS' && json.url) {
loader = me.document.getElementById(loadingId);
loader.setAttribute('src', link);
loader.setAttribute('_src', link);
loader.setAttribute('title', json.title || '');
loader.setAttribute('alt', json.original || '');
loader.removeAttribute('id');
domUtils.removeClasses(loader, 'loadingclass');
} else {
showErrorLoader && showErrorLoader(json.state);
}
}
} else {
showErrorLoader && showErrorLoader("上传失败");
}
form.reset();
}
};
// var uploadUrl = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params);
var uploadUrl = utils.formatUrl('http://static.01event.com/file/upload');
xhr.open("POST", uploadUrl,true);
//跨域
xhr.setRequestHeader('X-Requested-With','XMLHttpRequest');
xhr.withCredentials = false;
xhr.send(fd);
});