-
20 Feb 2011 1:34 AM #1
AjaxProxy with jsonData option?
AjaxProxy with jsonData option?
I've been using my own implementation of server-side feeders (Direct-like) for ExtJS stores for a long time since version 2, and thus I customized Store and HttpProxy in previous versions. Now I am learning the data concepts of version 4 and have started customizing AjaxProxy to get it communicate with my server-side code.
Basically, there would be just three customizations:- All actions, including read are requested via POST method, and
- All requests are made to the same URL, and
- All requests send JSON payload instead of POST fields, thus I need to use request.jsonData instead of request.params.
Is there any more simple and elegant solution to achieve my goals? If not, would the team consider an option for AjaxProxy that would enable sending data in JSON payload instead of HTTP fields? Thanks in advance.Code:Ext.define('Ext.data.MyProxy', { extend: 'Ext.data.AjaxProxy', alias: 'proxy.my', doRequest: function(operation, callback, scope) { var writer = this.getWriter(), request = this.buildRequest(operation, callback, scope); if (operation.allowWrite()) { request = writer.write(request); } Ext.apply(request, { headers : this.headers, timeout : this.timeout, jsonData : request.params, scope : this, callback : this.createRequestCallback(request, operation, callback, scope), method : this.getMethod(request), disableCaching: false // explicitly set it to false, ServerProxy handles caching }); delete request.params; Ext.Ajax.request(request); return request; }, constructor: function() { Ext.data.MyProxy.superclass.constructor.apply(this, arguments); this.actionMethods.read = 'POST'; } });
-
9 Dec 2011 12:41 AM #2
Thanks for posting this problem and providing your solution; it helped me make progress under a tight schedule.

Now I shall repay the favor: I was able to shorten your solution to the following by wrapping the buildRequest() function and modifying the request object therein.
Cheers.Code:var proxy = your_existing_store.getProxy(); proxy.__buildRequest__ = proxy.buildRequest; proxy.buildRequest = function(operation) { var request = this.__buildRequest__(arguments); Ext.apply(request, { params: null, jsonData: Ext.apply(request.params, { page: operation.page, start: operation.start, limit: operation.limit }) }); return request; }Last edited by sunaku; 9 Dec 2011 at 6:55 PM. Reason: pagination params were omitted
-
3 Oct 2012 2:50 PM #3
[SOLVED] by specifying actionMethods
[SOLVED] by specifying actionMethods
I found that ExtJS 4.1.1 lets us specify the HTTP method used to load data into a store:
In particular, notice the actionMethods property in the example above.Code:var store = Ext.create('Ext.data.Store', { proxy: { type: 'ajax', url: '...', actionMethods: { read : 'POST' // use HTTP POST when making the AJAX request } } });
-
4 Dec 2012 12:20 PM #4
I don't see how is this fixed?!! The issue is still there! Although we can alter the method from GET to POST, we can't send a JSON payload without overriding the doRequest method! I suggest that we offer the option to the user to achieve that.
-
4 Dec 2012 4:26 PM #5
See:
http://skirtlesden.com/articles/custom-proxies
The relevant example looks like this:
The framework has to be quite selective in allowing new config options in order to avoid bloat and conflicts. Proxies have several protected methods, like buildRequest, that are provided specifically to allow for these kind of customizations on a case-by-case basis.Code:Ext.define('MyApp.proxy.MyAppProxy', { ... buildRequest: function(operation) { var request = this.callParent(arguments); request.jsonData = request.params; request.params = {}; return request; }, getMethod: function(request) { return 'POST'; } });
I'd guess the reason Sencha hasn't added this as a formal feature is the difficulty in reconciling it with a writer.
-
5 Dec 2012 1:44 PM #6
Thank you very much skirtle. That makes more sense actually. And yeah, your article about custom proxies is very helpful! Thanks again :-)!
Similar Threads
-
AjaxProxy on failure
By h4m1d.r3z4 in forum Sencha Touch 1.x: DiscussionReplies: 0Last Post: 30 Jan 2011, 2:50 AM -
AjaxProxy 'POST' method ?!
By AndreaCammarata in forum Sencha Touch 1.x: DiscussionReplies: 5Last Post: 14 Oct 2010, 11:02 PM -
How to specify jsonData as option in store.load()?
By dbassett74 in forum Ext 3.x: Help & DiscussionReplies: 9Last Post: 16 Jul 2009, 5:34 PM -
[2.1][FIXED] Ext.Ajax.request jsonData option does not submit data
By kremlan in forum Ext 2.x: BugsReplies: 13Last Post: 22 May 2008, 6:32 AM


Reply With Quote