所以,我想我的问题很简单,但是我。。。有些问题:)
因此,在我用Django编写的应用程序中,我调用了使用Ajax创建Excel文件,如下所示:
$.ajax({
url: '/ajax-send-xls-desktop/',
type: 'POST',
contentType: "application/vnd.ms-excel",
data: JSON.stringify(data_xls),
dataType: 'text',
success: function(result) {
window.open('data:application/vnd.ms-excel,' + result);
}
});
在后台,我创建Excel文件并返回如下响应:
^{pr2}$我收到的都是很多字符:
N*8X"��1���Arial1���Arial1���Arial1���Arial1���Arial1���Arial1���Arial1���Arial
�General���� �� ���� �� ���� �� ���� �� ���� �� ���� �� ���� �� ���� �� ���� �� ���� ��
���� �� ���� �� ���� �� ���� �� ���� �� ���� �� �� �� �� �� �� �� ���`��Opis pozycji��
PDane wygnerowane przez Interzam - Internetowa Platforma Zarzdzania Zam�wieniamiSIDCPV
有人能确认问题出在字符集编码上吗?在
Data URI scheme提到base64编码作为一个选项。另一种方法是进行相关的字符编码。我建议你以64为基数对数据进行编码。Here is a question这将帮助你做到这一点。在
这对我有用:
我只是链接到查看网址和在结果对话框显示。有了ajax call它就无法完成。。。在
更新:
我找到了一个解决方案(使用了表单的iframe)来解决您需要在这里动态请求文件-Download a file by jQuery.Ajax。您可以使用@JohnCulviner-http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/或我的小函数
^{pr2}$ajax_download
创建的插件:在您的案例中(例如使用click事件):
你真的需要使用Ajax吗?它似乎过于复杂了。在
我的应用程序中有excel下载,但它们是标准的Django视图。其中大多数是基于类的泛型视图,我在其中重写了render_to_response方法,并用excel设置了内容类型。在
因此,我有一个对象的标准ListView来生成HTML,并且ExcelListView重写了render to response方法,来编写excel而不是将其传递给HTML模板。在
相关问题 更多 >
编程相关推荐