PDA

View Full Version : How carry out form submission using JSON, Ajax?



simonr26
18 Dec 2011, 5:12 AM
Hello,
Please can you specify how to carry out form submission using Ajax, JSON


I have a form with a submit handler as shown below. Ths sends data to
server using Ajax but not JSON.
Please can you inform me how this can be done - preferably using a not
too complicated mechanism.



handler: function() {
var form = this.up('form').getForm(); // get the basic form
if (form.isValid()) { // make sure the form contains valid data before submitting
form.submit({
url:'/dest/frm',
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
} else { // display error alert if the data is invalid
Ext.Msg.alert('Invalid Data', 'Please correct form errors.')
}
}




kind regards,
Simon

tobiu
18 Dec 2011, 6:54 AM
the default implementation of forms is not meant to wrap the params into a JSON string.

You can call form.getValues() instead submitting it and use a normal ext.ajax call and format the values to your needs using ext.encode or whatever.