开发者

Have a button that submits data without AJAX while other buttons submit through AJAX in EXT-JS

开发者 https://www.devze.com 2023-03-12 12:52 出处:网络
i have an EXT.formPanel in which i\'d like to have this beahaviour: two buttons should submit through ajax and one shouldn\'t. How to do this?

i have an EXT.formPanel in which i'd like to have this beahaviour: two buttons should submit through ajax and one shouldn't. How to do this?

This is my code:

    form = new Ext.FormPanel({
        frame:true,
        width:Ext.crl.styles.formWidth,
        title: 'Ricerca Atti',
        bodyStyle:'padding:5px 5px 0',
        defaultType: 'textfield',
        formId:'search-form',
        keys: [
            { key: [Ext.EventObject.ENTER], handler: function(){
                    ds.baseParams = form.getForm().getValues();
                    form.getForm().submit({url:urlRicerca,
                        waitMsg:'Ricerca in corso…', submitEmptyText: false, method:'GET',params: { start: 0, limit: PAGE_SIZE},
                        success:function(form,action) {Ext.crl.utils.searchOnSuccess(ds, action, grid); }
                    });
            }
            }
        ],
        items: [
            ricercaSemplice,
            ricercaAvanzata,
            { //This button should submit NOT submit through AJAX!!!
                text: 'Esporta Elenco',
                disabled:false,
                style: 'float:right;',
                xtype: 'button',
                handler: function() {
   开发者_如何学Go                 ds.baseParams = form.getForm().getValues();
                    form.getForm().submit({url:urlRicerca+".xls",
                        waitMsg:'Ricerca in corso…', submitEmptyText: false, method:'GET',params: { enableCsvFilter: "yes",  start: 0, limit: PAGE_SIZE},
                        success:function(form,action) {console.log(action); }
                    });
                }
            },{
                text: 'Reimposta',
                xtype: 'button',
                style: 'float:right;margin-right:10px',
                disabled: false,
                handler: function() {
                    form.getForm().reset();
                    //window.location.href = window.location.href;  
                }
            },{
                id: 'bottoreCercaRicerca',
                name: 'bottoreCercaRicerca',
                text: 'Cerca',
                xtype: 'button',
                style: 'float:right;margin-right:10px',
                disabled: false,
                handler: function() {
                    ds.baseParams = form.getForm().getValues();
                    form.getForm().submit({url:urlRicerca,
                        waitMsg:'Ricerca in corso…', submitEmptyText: false, method:'GET',params: { start: 0, limit: PAGE_SIZE},
                        success:function(form,action) {Ext.crl.utils.searchOnSuccess(ds, action, grid); }
                    });
                }
            },{
                name: 'buttonSwitchRicerca',
                xtype: 'button',
                style: 'margin-bottom:10px',
                text: 'Ricerca Avanzata',
                handler: function() {
                    if(ricercaAvanzata.hidden) {
                        this.setText('Ricerca Standard');
                        ricercaAvanzata.show();
                    }
                    else {
                        this.setText('Ricerca Avanzata');
                        ricercaAvanzata.hide();
                    }
                }
            },
            DEFAULT_SPACER,
            Ext.crl.modalitaLavoro.comboModalitalavoro
        ]
    });

I'v written a comment on where the button should NOT use ajax.

EDIT - i've found a solution, this is an handler that works for not submitting through ajax (actually the fact that opens in a new window is something i want) what i need. Are there any other options?

                handler: function() {
                    query = form.getForm().getValues(true);
                    query += "&enableCsvFilter=yes";
                    var url = urlRicerca + ".xls?" + query;
                    window.open(url);
                }


Here is an example :

var ajaxButton1 = new Ext.Button({text:'ajaxButton1 ', handler:ajaxButton1Function});
var ajaxButton2 = new Ext.Button({text:'ajaxButton2 ', handler:ajaxButton2Function});
var noAjaxButton = new Ext.Button({text:'noAjaxButton ', handler:noAjaxButtonFunction});
function ajaxButton1Function(){
    Ext.Ajax.Request({
        url: 'your url', // you can fix a parameter like this : url?action=anAction1
        method: 'POST',
        params: {
            myField1: myField1.getValue()
            // all your params.... 
        },
        success: function (result, request){
            alert('Succesfully added ' + result.responseText);
        },
        failure: function (result, request){
            alert('Error in server' + result.responseText);
        }
  });
}


function ajaxButton2Function(){
    Ext.Ajax.Request({
        url: 'your url', // you can fix a parameter like this : url?action=anAction2
        method: 'POST',
        params: {
            myField1: myField1.getValue()
            // all your params.... 
        }
        success: function (result, request){
            alert('Succesfully added ' + result.responseText);
        },
        failure: function (result, request){
            alert('Error in server' + result.responseText);
        }
  });
}

function noAjaxButtonFunction(){
    form.submit({
       success: function(form, action) {
            Ext.Msg.alert('Success', action.result.msg);
       },
       failure: function(form, action) {
            Ext.Msg.alert('Failed', action.result.msg);
       }
   });
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号