【问题标题】:Blueimp jQuery file upload force iFrame Transport server responseBlueimp jQuery 文件上传强制 iFrame Transport 服务器响应
【发布时间】:2015-07-14 16:05:30
【问题描述】:

我正在使用 Blueimp JQuery 文件上传,带有选项 forceIframeTransport: true,我能够将文件和表单字段上传到跨域端点进行处理。

但是,服务器响应让我困扰了很长时间。

我发现了一个关于图书馆的在线资料:

http://missioncriticallabs.com/blog/lessons-learned-from-jquery-file-upload

我已按照链接的说明进行操作,但未能正确获得服务器响应。

这是我的代码:

jQuery("#newFile").fileupload({
        url: "https://mydomain/cgi-bin/get_file.cgi",
        forceIframeTransport: true,
        type: "POST",
        cache: false,
        contentType: false,
        processData: false,
        autoUpload: false,
        replaceFileInput: false
        done: function(e, data) {

            console.log("done");
            console.log(e);
            console.log(data.result);
        }
});

目前,我的服务器端点只打印 JSON 响应:

#!C:/Perl64/bin/perl.exe

use CGI;
use JSON;

print "Content-type: text/plain; charset=iso-8859-1\n\n";
#print header("application/json;charset=UTF-8");
my %rawText = (message => "Processed");
my $json = encode_json \%rawText;
print $json;

我尝试将标头打印为“text/plain”和“application/json”,但无法在 JS 代码中的“done”函数中获得服务器响应。

我的 console.log(data.result) 总是打印“未定义”。

我对图书馆及其背后的概念非常陌生,

如果有人能指导我使用该库,我将不胜感激。

非常感谢。

【问题讨论】:

    标签: ajax json perl cgi jquery-file-upload


    【解决方案1】:

    为了使小部件与 Perl 一起工作,您必须 implement a custom server-side upload handler。您的 CGI 脚本必须以文档中描述的格式返回 JSON 响应。

    幸运的是,有人已经为您完成了这项工作。看看 CPAN 上的模块 jQuery::File::Upload

    【讨论】:

      猜你喜欢
      • 2012-09-06
      • 1970-01-01
      • 1970-01-01
      • 2014-03-22
      • 2011-05-15
      • 2013-04-29
      • 2015-09-29
      • 2014-06-18
      • 1970-01-01
      相关资源
      最近更新 更多