Jas*_*lls 5 jquery file download
当我的用户选择生成报告时,我正在使用John Culviner的文件下载插件来生成"请稍候"消息.
当用户单击链接时,我向我的PHP发送ajax请求,该请求在服务器上生成PDF.那时我正在尝试更新fileDownload插件的成功处理程序中的链接.
我可能正在接近这个错误,但这是我的代码 - 非常感谢任何帮助.
$("body").on("click","##pdfLink", function(e){
$.fileDownload($(this).attr('href'), {
preparingMessageHtml: "Preparing your report, please wait...",
failMessageHtml: "There was a problem generating your report, please try again."
});
// Build our data string.
var strData = {method: "createPDF"};
// Send a request to build our XL file.
$.ajax({
url: '/pdf.php',
data: strData,
type: 'get',
dataType: 'json',
success: function(data) {
alert(data);
$("##pdfLink").attr("href","/pdf/"+data);
},
error: function(e) {
console.log(e);
}
});
return false;
e.preventDefault();
})
Run Code Online (Sandbox Code Playgroud)
此时,当我单击链接时,模式会正确显示"请等待"消息.我的文件确实构建在服务器上(在我的成功处理程序中通过我的警报确认),我的HREF确实得到了更新.但是,该插件不会提示用户下载.
谢谢!
你尝试过调整你的超时时间吗?
$.ajax({
url: '/pdf.php',
data: strData,
type: 'get',
dataType: 'json',
timeout: 10000,
success: function(data) {
alert(data);
$("##pdfLink").attr("href","/pdf/"+data);
},
error: function(e) {
console.log(e);
}
});
return false;
e.preventDefault();
Run Code Online (Sandbox Code Playgroud)