为什么在extjs表单提交中不调用成功回调?

Sae*_*ati 10 extjs file-upload extjs4

我正在尝试使用Ext JS表单上传文件,如果成功或失败,请显示相应的消息.但我无法获得理想的结果.我无法制作successfailure回调作品form.submit.

我到现在所做的是:

使用此脚本创建表单:

new Ext.FormPanel({
    fileUpload: true,
    frame: true,
    url: '/profiler/certificate/update',
    success: function() {
        console.log(arguments);
    },
    failure: function() {
        console.log(arguments);
    }
}).getForm().submit()


?/*
    The response Content-Type is text/html (with charcode=utf8);
    The response JSON is: { "success": true }
*/??
Run Code Online (Sandbox Code Playgroud)

设置响应Content-Typetext/html基于这个答案.
基于Ext JS文档发回适当的JSON结果.通过Fiddler捕获的回复是:

{"success":false}
Run Code Online (Sandbox Code Playgroud)

要么

{"success":true}
Run Code Online (Sandbox Code Playgroud)

我甚至将响应Content-Type设置为application/json.但仍然没有成功.

我读过类似链接这个这个,但他们没有帮助.请注意,我还尝试了另一个创建表单的脚本,其中包含一个上传字段和一个保存按钮,我在保存按钮的处理程序中提交了表单.但仍然没有引发回调.

bhu*_*ten 10

这是一个工作示例 - Javascript代码:

Ext.onReady(function () {

    Ext.define('ImagePanel', {
        extend: 'Ext.form.Panel',
        fileUpload: true,
        title: 'Upload Panel',
        width: 300,
        height: 100,

        onUpload: function () {
            this.getForm().submit({
                url: 'upload.php',
                scope: this,
                success: function (formPanel, action) {
                    var data = Ext.decode(action.response.responseText);
                    alert("Success: " + data.msg);
                },
                failure: function (formPanel, action) {
                    var data = Ext.decode(action.response.responseText);
                    alert("Failure: " + data.msg);
                }
            });
        },

        initComponent: function () {
            var config = {
                items: [
                    {
                        xtype: 'fileuploadfield',
                        buttonText: 'Upload',
                        name: 'uploadedFile',
                        listeners: {
                            'change': {
                                scope: this,
                                fn: function (field, e) {
                                    this.onUpload();
                                }
                            }
                        }
                    }
                ]
            };

            Ext.apply(this, Ext.apply(this.initialConfig, config));
            this.callParent(arguments);
        }
    });


    var panel = Ext.create('ImagePanel', {
        renderTo: Ext.getBody()
    });
});
Run Code Online (Sandbox Code Playgroud)

和PHP代码:

<?php
if (isset($_FILES)) {
    $temp_file_name = $_FILES['uploadedFile']['tmp_name'];
    $original_file_name = $_FILES['uploadedFile']['name'];

    echo '{"success": true, "msg": "'.$original_file_name.'"}';

} else {
    echo '{"success": false, "msg": "No Files"}';
}
Run Code Online (Sandbox Code Playgroud)

  • 只是工作,但我仍然不理解这个理论.作为开发人员,另一次我说*该死的Ext JS*. (5认同)