form.submit 在 ExtJS 中上传文件时不工作

form.submit not working while file upload in ExtJS

我正在使用 ExtJS 4.2.0 上传文件功能。但是当我尝试使用 form.submit() 上传时,它给了我一个 ExtJS 错误并且没有调用该服务。下面是表单面板的代码:

    Ext.define('modelname.view.AttachDocumentPanel', {
    extend: 'Ext.form.Panel',
    alias: 'widget.attachdocumentpanel',
    id: 'attachdocumentpanel',
    itemId: 'attachdocumentpanel',
    name: 'attachdocumentpanel',
    height:25,
    layout:'column',
    requires: [
        'modelname.common.Util'     
    ],

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [             
                {
                    xtype: 'filefield',
                    itemId: 'fileUploadField', 
                    id: 'fileUploadField',
                    name: 'fileUploadField',
                    emptyText : 'Select a file to upload',
                    msgTarget: 'side',
                    allowBlank: false,
                    anchor: '100%',
                    hideLabel: true,
                    columnWidth: .25,
                    buttonText: 'Browse'
                },
                {
                    xtype : 'button',
                    text : 'Upload',
                    columnWidth: .75,
                    itemId: 'uploadDocumentButton', 
                    name: 'uploadDocumentButton'
                }
              ]
        });
        me.callParent(arguments);
    }   
});

上传按钮的处理程序代码在控制器中 class:

    onUploadClick: function(button) {               
    var form = button.up('attachdocumentpanel').getForm();
    var fileName2 = Ext.getCmp("fileUploadField").getValue();

    if(Ext.isEmpty(fileName2)) {
        Ext.Msg.alert('Warning','No file selected !');
        form.reset();
        return;
    }

    if (form.isValid()) {
        form.submit({
                    url: 'http://localhost:8080/WAR_project/rest/service/ticket/uploadfile',
                    waitMsg:'Uploading document...',
                    success: function(form, action) {
                        Ext.Msg.alert('Success', action.result.msg);
                    },
                    failure: function(form, action) {
                        Ext.Msg.alert('Failure', action.result.msg);
                        }
                });
    }

    }

点击上传时,出现了一些 ExtJS 一般错误,提示 a 未定义。请帮忙。

这对我有用。试试这个

  if (form.isValid()) {
        form.submit({

                    url: 'http://localhost:8080/WAR_project/rest/service/ticket/uploadfile',
                    waitMsg: 'Uploading Please Wait...',
                    method: 'POST',                    
                    success: function (r, a) {
                       console.log('success message here')
                    },
                    failure: function (r, a) {                    
                         console.log('failure message here')
                    }
                });
}