PDA

View Full Version : Is there any way to get a FormPanel to submit JSON?



Ranma13
4 Feb 2010, 3:19 AM
By default, a FormPanel submits data as application/x-www-form-urlencoded. Is there any way to get it to submit JSON instead?

Drayton
4 Feb 2010, 4:17 AM
Something like this?


new Ext.Window({
title: 'jsontest',
width: 400,
height: 400,
closable: true,
items: [{
xtype: 'form',
id: 'myFormPanel',
defaultType: 'textfield',
items: [{name: 'value1'},{name: 'value2'}]
}],
buttons: [{
text: 'submit',
handler: function(){
var f = Ext.getCmp('myFormPanel').getForm();
Ext.Ajax.request({
url: 'submithandler.php',
headers: {'Content-Type':'application/json; charset=utf-8'},
params: Ext.util.JSON.encode(f.getValues());
});
}
}]
}).show();