我正在使用blueimp jquery文件上传,并带有option forceiframetransport:true,我能够上传文件并表单字段到跨域端点进行处理。
但是,服务器响应很长时间以来困扰着我。
我遇到了有关图书馆的在线材料:
http://smissioncriticallabs.com/blog/lesson-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-1nn";
#print header("application/json;charset=UTF-8");
my %rawText = (message => "Processed");
my $json = encode_json %rawText;
print $json;
我试图将标题打印为" text/plain"one_answers" application/json",但是我无法在JS代码中的"完成"函数中获得服务器响应。
我的console.log(data.result)总是打印"未定义"。
我很崭新,在图书馆和背后的概念中,
因此,如果有人可以指导我使用图书馆,我将非常感谢。
非常感谢。
为了使小部件与perl一起使用,您必须实现自定义的服务器端上传处理程序。您的CGI脚本必须以文档中描述的格式返回JSON依据。
幸运的是,有人已经为您完成了工作。看看模块jquery :: file ::上传CPAN。