PDA

View Full Version : How to use Ext.data.proxy.Ajax



alexmcmillan
8 Apr 2014, 4:55 PM
I have an Oracle Application Express application with an API available for interacting with the database via AJAX. I am trying to send GET/POST requests, but Application Express uses a different URL syntax than is tradition. As I understand it, most GET requests use a syntax of the form: www.example.com/test?myVar=123&myVar2=456 but Application Express requires variables be passed in 2 colon-delimited strings to a single parameter, named 'p': www.example.com/test?p=myVar,myVar2:123,456. Is it possible to have an Ext.data.proxy.Ajax configuration that will pass information in this way? It appears that the "api" config allows specifying individual URLs for CRUD requests, but I haven't found any information for customising the usage of variables.

evant
8 Apr 2014, 6:20 PM
No, there's no such configuration. To roll your own, you'd want to extend Ext.data.proxy.Ajax and override the getParams method.

alexmcmillan
8 Apr 2014, 6:49 PM
Thanks for your reply, however according to the Sencha docs (http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.data.proxy.Ajax), there is no 'getParams' method to override...

skirtle
9 Apr 2014, 1:25 AM
getParams is in the docs but it's marked as private. That doesn't stop you overriding it.

If you want a non-private method instead you could use buildRequest. Some examples here:

http://skirtlesden.com/articles/custom-proxies

alexmcmillan
9 Apr 2014, 2:38 PM
Wow Skirtle - that is an awesome article that will definitely help me with my current project. I'll be checking out the others in your 'den' for sure.

I can't see any documentation for 'getParams' - how do I display these private configs?

You use an override to getMethod that returns 'POST' in every case so that all requests use POST. Is this any different from specifying a config of actionMethods: 'POST'?

Also, there are some parameters I need to send on every request. As my proxy extends Ext.data.proxy.Ajax, which has a config object "extraParams", I placed them there. However, they do not appear in any requests.

If I place them in the 'proxy' configuration object within my store, they DO appear in requests.

I was of the impression that my store.proxy object was simply adding unique configuration to my (generic) extended Ext.data.proxy.Ajax?

This works perfectly:


buildRequest: function (operation) {
var request,
params;

request = this.callParent(arguments);
params = request.params;

params.p_request = 'APPLICATION_PROCESS=APP_DOCUMENT_CRUD';
params.p_instance = Ext.get('pInstance').dom.value;
params.p_flow_id = Ext.get('pFlowId').dom.value;
params.p_flow_step_id = Ext.get('pFlowStepId').dom.value;

return request;
},

skirtle
10 Apr 2014, 2:48 AM
I can't see any documentation for 'getParams' - how do I display these private configs?

It'll show up if you type its name into the search box, top right. To browse all private methods click on the 'Show' menu, also on the right, within the class docs.


You use an override to getMethod that returns 'POST' in every case so that all requests use POST. Is this any different from specifying a config of actionMethods: 'POST'?

I was primarily trying to demonstrate the use of the method. As I explain in the article its use isn't really required for such a simple case. I don't believe you can set actionMethods: 'POST' as a string directly, you need to pass it an object with each of the four actions.


Also, there are some parameters I need to send on every request. As my proxy extends Ext.data.proxy.Ajax, which has a config object "extraParams", I placed them there. However, they do not appear in any requests.

That's a library bug, it doesn't pick up extraParams from the prototype. See my answer here:

http://www.sencha.com/forum/showthread.php?281840

alexmcmillan
10 Apr 2014, 3:06 AM
It'll show up if you type its name into the search box, top right. To browse all private methods click on the 'Show' menu, also on the right, within the class docs.

Thank you very much - I hadn't seen that "show" menu. That'll no doubt help me a lot from now on.


I was primarily trying to demonstrate the use of the method. As I explain in the article its use isn't really required for such a simple case. I don't believe you can set actionMethods: 'POST' as a string directly, you need to pass it an object with each of the four actions.

Understood.

You're right - I saw somebody using it that way (with just a string) somewhere else a few minutes before that post, but yes - it needs to be an object using {action : method}. That method looks very handy as well tho - thanks :)


That's a library bug, it doesn't pick up extraParams from the prototype. See my answer here:

http://www.sencha.com/forum/showthread.php?281840

Again, thank you very much. I'm sure I could pick your brain for a long time but I don't want to be a pain (and I don't expect you to teach me the whole framework! lol)

Please continue to make articles on your blog - it's difficult to find such helpful nuggets of information online. I really appreciate your time and effort. I'll leave you be now :)