我的代码在Chrome中运行良好,但在IE中出错。消息是:
清空文件上传结果
和IE显示跨站点脚本错误消息。但文件上传效果很好。
我只用我的服务器链接更改了“main.js”。
$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
// url: 'server/php/'
url: './jQuery-File-Upload-master/server/php/'
});
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'./jQuery-File-Upload-master/cors/result.html?%s'
)
);
if (window.location.hostname === 'mimong4.cafe24.com') {
// Demo settings:
$('#fileupload').fileupload('option', {
url: './jQuery-File-Upload-master/server/php/index.php',
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/I,
process: [
{
action: 'load',
fileTypes: /^image\/(gif|jpeg|png)$/,
maxFileSize: 20000000 // 20MB
},
{
action: 'resize',
maxWidth: 1440,
maxHeight: 900
},
{
action: 'save'
}
]
});
// Upload server status check for browsers with CORS support:
if ($.support.cors) {
$.ajax({
url: './jQuery-File-Upload-master/server/php/index.php',
type: 'HEAD'
}).fail(function () {
$('<span class="alert alert-error"/>')
.text('Upload server currently unavailable - ' +
new Date())
.appendTo('#fileupload');
});
}
} else {
// Load existing files:
$.ajax({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: $('#fileupload').fileupload('option', 'url'),
dataType: 'json',
context: $('#fileupload')[0]
}).done(function (result) {
$(this).fileupload('option', 'done')
.call(this, null, {result: result});
});
}
});
答案 0 :(得分:3)
IE9使用跨站点iframe传输。
第3个参数应该是指向cors / result.html的url,它应该位于原始服务器(而不是您的上传服务器)上,以克服跨域问题。
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
'http://mimong4.cafe24.com/result.html?%s'
)
);
https://github.com/blueimp/jQuery-File-Upload/wiki/Cross-domain-uploads