在前台用easyui调用后台下载的action类时,未能弹出下载框。最开始我是在datagrid的toolbar中添加的下载按钮,其部分代码如下:
toolbar:[
{
text:'Generate',
iconCls:'icon-orange' ,
handler:function(){
$.messager.confirm('Prompt Msg', 'Do you want to generate the configuration?', function(r){
if(r){
$.post('${pageContext.request.contextPath}/ssGeneratorAction!SSGeneration', function(result){
$('#t_user').datagrid('reload');
$.messager.show({
title: 'Prompt Msg',
msg: 'Configuration generated successfully!'
});
});
} else {
return;
}
});
}
},{
text:'Download',
iconCls:'icon-save' ,
handler:function(){
$.messager.confirm('Prompt Msg', 'Do you want to download the configuration file?', function(r){
if(r){
$.post('${pageContext.request.contextPath}/ssCfgDownloadAction.action', function(result){
$('#t_user').datagrid('reload');
$.messager.show({
title: 'Prompt Msg',
msg: 'Configuration downloaded successfully!'
});
});
} else {
return;
}
});
}
}
]
未能弹出下载框的原因是,不能用异步的方式来调用下载的action,直接用href就行了。于是修改toolbar的属性,
toolbar: "#tb"
然后添加tb的定义:
<div id="tb">
<a id="btn1" class="easyui-linkbutton" iconCls="icon-orange" plain="true">Generate</a>
<a id="btn2" href="${pageContext.request.contextPath}/ssCfgDownloadAction.action" class="easyui-linkbutton" iconCls="icon-save" plain="true">Download</a>
</div>
以及btn1的click函数:
$('#btn1').click(function(){
$.messager.confirm('Prompt Msg', 'Do you want to generate the configuration?', function(r){
if(r){
$.post('${pageContext.request.contextPath}/ssGeneratorAction!SSGeneration', function(result){
$('#t_user').datagrid('reload');
$.messager.show({
title: 'Prompt Msg',
msg: 'Configuration generated successfully!'
});
});
} else {
return;
}
});
});