javascript - 当 isUpload 为真时,Ext.Ajax.request 回调从不调用

标签 javascript ajax extjs

我正在使用 ExtJS 制作一个表单,该表单以 CSV 格式从数据库中的数据生成报告。在用户选择一个简单的日期范围来提取数据并提交后,运行以下代码:

var frm = document.createElement('form');
frm.id = 'frmDummy';
frm.name = id;
document.body.appendChild(frm);

Ext.MessageBox.wait('Generating CSV File ...');

Ext.Ajax.request({
    url: 'csv_extract_ajax.php?start_time='+txtDateFieldFrom.getRawValue()+'&end_time='+txtDateFieldTo.getRawValue(),

    method : 'POST',

    form: Ext.fly('frmDummy'),

    isUpload: true, 

    success: function(o, r, n){

        Ext.MessageBox.updateProgress(1);
        Ext.MessageBox.hide();
    },

    failure: function(o, r, n){

        Ext.MessageBox.updateProgress(1);
        Ext.MessageBox.hide();
    },

    callback: function(o, r, n){

        Ext.MessageBox.updateProgress(1);
        Ext.MessageBox.hide();
    },     

    scope: this
});

关联的 php 文件简单地输出一个 CSV 字符串,工作文件。

由于 isUpload 为真,回调似乎永远不会返回给用户。一旦我删除它,就会调用回调,但文件不会上传到客户端。

现在的问题是,一切正常,但 MessageBox 永远不会消失,因为从未调用过回调(成功、失败或回调)

有什么想法吗? :P

附加信息:

PHP header :

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Accept-Ranges: bytes");

最佳答案

这是 Ext.Ajax.request 文档的摘录:

isUpload : Boolean (Optional) True if the form object is a file upload (will usually be automatically detected). File uploads are not performed using normal "Ajax" techniques, that is they are not performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the DOM element temporarily modified to have its target set to refer to a dynamically generated, hidden which is inserted into the document but removed after the return data has been gathered. The server response is parsed by the browser to create the document for the IFRAME. If the server is using JSON to send the return object, then the Content-Type header must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body. The response text is retrieved from the document, and a fake XMLHttpRequest object is created containing a responseText property in order to conform to the requirements of event handlers and callbacks. Be aware that file upload packets are sent with the content type multipart/form and some server technologies (notably Java EE) may require some custom processing in order to retrieve parameter names and parameter values from the packet content.

如您所见,上传请求通过 IFRAME 返回,并且仅模拟标准 AJAX 响应,因此不会调用回调。

关于javascript - 当 isUpload 为真时,Ext.Ajax.request 回调从不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1123334/

相关文章:

javascript - 如何使用慢速函数 setTimeout()

javascript - 防止同步加载商店

javascript - 从 Sencha Touch 1.1.x 迁移到 Sencha Touch 2

javascript - axios-mock-adapter 与预期的 url 不匹配

javascript - typescript : Handling import from external libraries

javascript - 为jquery中的特定文本设置背景颜色

javascript - AJAX 请求在家里可以工作,但在我的学校不行

JQuery Ajax,ASP.NET MVC 5 中没有运行回调函数

php - 将HTML表单的输入数据插入JSON对象,然后将其存储在MYSQL中

javascript - 为 ExtJs 中的多个 Controller 绑定(bind)事件