的形式.在ExtJS中上传文件时提交不工作

form.submit not working while file upload in ExtJS

本文关键字:文件 提交 工作 ExtJS      更新时间:2023-09-26

我使用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);
    }   
});

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

    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')
                    }
                });
}