PDA

View Full Version : config to default all request methods in app to POST?



JohnJones357
9 Jul 2014, 7:34 AM
I was thinking there might be some config like in Ext.application for example that might default all requests to POST. But i cant seem to find a config that can do this. Is there an easy way to default all requests in my app to POST?

Thanks

greg.barry
16 Jul 2014, 8:51 AM
You could define a base class and extend Ext.data.Connection. Then add the post method to your base class. Then you can use that class instead of Ext.ajax.Request. For example:


Ext.define('Fiddle.Ajax', {
extend: 'Ext.data.Connection',
singleton: true,
url: 'fake.php',
method: 'POST'
});


Fiddle.Ajax.request({
params: {
foo: 'bar'
}
});

skirtle
16 Jul 2014, 10:13 PM
The question is quite open-ended as you haven't specified what you mean by 'default'.

Greg's suggestion works fine if you're just concerned with direct calls to request but it won't affect proxies. You could alternatively set Ext.Ajax.method = 'POST' (again, proxies explicitly set their method so won't be affected).

Something like this would force all requests to use POST, something much stronger than a 'default':


Ext.Ajax.on('beforerequest', function(conn, options) {
options.method = 'POST';
});