【发布时间】: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