在Ext Js中生成保存为AJAX请求的对话框 [英] Generate save as dialog box with AJAX request in Ext Js

查看:182
本文介绍了在Ext Js中生成保存为AJAX请求的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含网格和按钮的应用程序,用户可以将网格导出到excel。当服务器使用excel文件进​​行响应时,我希望能够显示保存为对话框。服务器将参数接受为JSON对象。这是我的代码: -

I have an application that contains a grid and button for the user to be able to export the grid to excel. I want to be able to show the save as dialog box when the server responds with the excel file.The server accepts the parameters as a JSON object. Here is my code:-

Ext.Ajax.request({
   url: '/export/excel/',
   method: 'POST',
   //Send the query as the message body
   jsonData: jsonStr,
   success: function (result,request) {
        Ext.DomHelper.append(document.body, {
           tag: 'iframe',
            frameBorder: 0,
            width: 0,
            height: 0,
            //src:result,
            css: 'display:none;visibility:hidden;height:1px;'
        });
    }, //success
    failure: function (response, opts) {
        var msg = 'server-side failure with status code: ' + response.status + ' message: ' + response.statusText;
        Ext.Msg.alert('Error Message', msg);
    }
});

我知道有一个类似的问题( ExtJS AJAX保存为对话框),但是引用了服务器上的静态文件。在我的情况下,根据发送的json结果是每次都会有所不同。我得到我想要的结果.responseText的整个excel文件。需要做什么才能弹出对话框,要求用户保存为选项?另外,我不知道如何配置domhelper中的 src 。任何帮助将非常感激。

I know there is a similar question ( ExtJS AJAX save as dialog box) but that references a static file on the server.In my case, depending upon the json sent the result is going to be different each time. I get back the entire excel file that i want in the result.responseText. What needs to be done so that the dialog box popup up asking the user for save as options? Also, im not sure how the src in the domhelper should be configured. Any help would be really appreciated.

推荐答案

我使服务器端返回创建和保存文件的位置的路径,而不是在响应中作为附件发送文件,因此避免了在响应中设置头部的问题。然后我只是将代码中的iframe的源代码设置为响应中返回的路径( result.responseText )。

I made the server side return the path of the location the file is created and saved, instead of sending the file as an attachment in the response and hence avoiding the problem of setting the headers in the response. Then i just set the source of the iframe in the code to the path that gets returned in the response (result.responseText).

这篇关于在Ext Js中生成保存为AJAX请求的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆