PDA

View Full Version : ajax requests and form submit



yumusakg
30 Nov 2010, 2:43 AM
i have a window consists of a form and editorgridpanel. after save button clicked, both of them are saved, form and the editorgridpanel. editorgridpanel has multiple rows and ajax request is called for each of them.
my problem is when to alert "successfully saved" message or vice versa in case of error.

form submit
ajax request 1
ajax request 2
ajax request 3
.
.
.

some ajax requests are skipped if not necessary.

how can i show all errors after the last request is called?

Condor
30 Nov 2010, 3:42 AM
I would never do this with multiple AJAX requests. I would rewrite the form submit, so it also submits the grid data.

yumusakg
30 Nov 2010, 3:47 AM
Condor,

i haven't any idea how to do it, could you post an example?

Condor
30 Nov 2010, 4:51 AM
In the beforeaction of the form, collect all the grid data and store it in action.options.params.

The problem is that Submit does a x-www-form-urlencoded or multipart/form-data POST, it won't send the data as JSON. This means you either have to extend Ext.form.Action.Submit (to make it use jsonData instead of params) or you have to find a way to convert the grid data to x-www-form-urlencoded.

yumusakg
30 Nov 2010, 6:24 AM
Thanks Condor,

the answer was in your previous replies :)

http://www.sencha.com/forum/showthread.php?83651-Sending-multiple-grid-data-Rows-through-AJAX&p=542123#post542123

The code like below worked for me;



var gridData = [];
var grid = Ext.getCmp('grid_tank');
grid.getStore().each(function(record) {
gridData.push(record.data);
});

form.getForm().submit({
waitMsg: 'updating',
url: 'data.aspx',
params: {
cmd: 'update',
gridData: Ext.encode(gridData)
},
success: function(f, a) {
Ext.Msg.alert(a.result.title, a.result.msg);
},
failure: function(f, a) {
Ext.Msg.alert(a.result.title, a.result.msg);
}
});