2017-06-06 78 views
0

我有一個按鈕,創建一個隱藏的表單,並調用form.dom.submit()上點擊。我需要添加成功和失敗回調才能提交操作。 下面的代碼:ExtJS的4:添加成功/失敗回調form.dom.submit()動作

Ext.define("DownloadButton", { 
    extend: 'Ext.button.Button', 
    download: function (me, event) { 
    this.form.dom.submit(); 
    }, 
    initComponent: function() { 
    this.handler = Ext.Function.bind(this.download, this.scope || this); 
    this.callParent(arguments); 
    }, 
    afterRender: function() { 
    this.callParent(arguments); 
    this.form = this.getEl().createChild({ 
     tag: 'form', 
     cls: 'x-hidden', 
     method: 'POST', 
     action: this.fileUrl, 
     target: this.getId() + '-form-iframe' 
    }); 
    this.getEl().appendChild(this.form); 
    } 
}); 

嘗試添加PARAMS提交

this.form.dom.submit({ 
    success: function(response) { 
    console.log('success'); 
    }, 
    failure: function(response) { 
    console.log('failure'); 
    } 
}); 

但這並沒有幫助。

+0

你能創建一個例如小提琴這個?可以解決那裏的問題。 –

+0

是否有任何理由使用表單?你發送了什麼數據? – MarthyM

回答

0

您正在創建的,而不是ExtJS的form形式DOM元素。

當你創建一個ExtJS form,你可以調用其optionssubmit方法,包括successfailure。當你standardSubmit選項設置爲true,然後你可以設置target選項。

像這樣的東西應該工作:

// Form creation 
this.form = Ext.create('Ext.form.Panel', { 
    hidden: true, 
    method: 'POST', 
    url: this.fileUrl, 
    standardSubmit: true, 
}); 

// Form submit 
var target = this.getId() + '-form-iframe'; 
this.form.submit({ 
    target: target, 
    success: function(response) { 
     console.log('success'); 
    }, 
    failure: function(response) { 
     console.log('failure'); 
    } 
}); 

不過,我看不出有任何理由使用一個隱藏的表單,當你可以使用一個簡單AJAX request

Ext.Ajax.request({ 
    url: this.fileUrl, 
    success: function(response) { 
     console.log('success'); 
    }, 
    failure: function(response) { 
     console.log('failure'); 
    } 
});