首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IE9中的jQuery图像上传(blueimp)报告错误

IE9中的jQuery图像上传(blueimp)报告错误
EN

Stack Overflow用户
提问于 2013-01-01 15:39:38
回答 1查看 1.9K关注 0票数 0

我的代码在Chrome中运行良好,但在IE中会出错。其信息是:

空文件上传结果

IE显示了一个跨站点脚本错误消息。但是文件上传效果很好。

我只用服务器链接更改了"main.js“。

代码语言:javascript
复制
$(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});
    });
}

});
EN

回答 1

Stack Overflow用户

发布于 2013-01-11 07:48:49

IE9使用跨站点iframe传输。

第三个参数应该是指向cors/result.html的url,它应该位于源服务器(而不是上传服务器)上,以克服跨域问题。

代码语言:javascript
复制
// 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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14111754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档