0

我的代码在 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});
    });
}

});
4

1 回答 1

3

IE9 使用跨站点 iframe 传输。

第三个参数应该是指向 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

于 2013-01-11T07:48:49.053 回答