2017-06-06 13 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); 
    } 
}); 

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

を提出するのparamsを追加しようとしました。しかし、これは助けにはなりませんでした。

+0

が作成できますこれのための例のフィドル?そこの問題を解決することができます。 –

+0

フォームを使用する理由はありますか?どのデータを送信していますか? – MarthyM

答えて

0

ExtJS formではなく、フォームDOM要素を作成しています。あなたはExtJSのformを作成するとき

は、あなたがsuccessfailureを含め、そのoptionssubmitメソッドを呼び出すことができます。 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'); 
    } 
}); 
関連する問題