-
21 Oct 2011 12:58 AM #1
Answered: How to send JSON data via 'ajax' proxy to a server by using store.load()?
Answered: How to send JSON data via 'ajax' proxy to a server by using store.load()?
Hey,
how can I add some extra data to my request via a store proxy? The config 'extraParams:' in the proxy's config can only pass normal http parameters with a POST or GET request to the server. Is there a possibility to add custom data like JSON encoded strings to the server?
Thanks in advance!
-
Best Answer Posted by silent
I've found a solution!
Jayrock is able to process GET requests. I stumbled about at http://groups.google.com/group/jayro...39d07a7635cc51 where Atif Aziz links to a good documentation of Jayrock: http://json-rpc.org/wd/JSON-RPC-1-1-...tProcedureCall
Just a few things to change on the project files:
1. Change on serverside the .NET [JsonRpcMethod("myJayrockNETMethod")] to [JsonRpcMethod("myJayrockNETMethod", Idempotent = true)] to enable GET requests and let jayrock handle the passing parameters.
2. Change your store's proxy 'url:' to '/path/to/yourHandler.ashx/myJayrockNETMethod' to let Ext know, thtt there is the location to pass parameters to.
3. Also change in the proxy config the 'extraParams:' (only if your 'myJayrockNETMethod' needs parameters), just assign in simple "key": "value" notation, like:
Ext will encode the parameters to something like '/path/to/yourHandler.ashx/myJayrockNETMethod?user=peter&site=marketplace'Code:[...] extraParams: { "user": "peter", "site": "marketplace" } [...]
If there are some special chars in the string, they will be encoded. Also a good place to experiment with url-encodings: http://www.albionresearch.com/misc/urlencode.php
Greetings, silent
-
21 Oct 2011 1:05 AM #2
-
21 Oct 2011 1:14 AM #3
-
21 Oct 2011 1:19 AM #4
-
21 Oct 2011 2:21 AM #5
-
21 Oct 2011 2:28 AM #6
The data can be passed only as a string and will have to be converted into JSON object by your server side technology. This is the same case as we receive an Ajax response and to use it we first decode it through ExtJS.
Which server side technology are you using? Like in PHP, we have json_decode for the same purpose - http://php.net/manual/en/function.json-decode.php
-
21 Oct 2011 2:44 AM #7
-
21 Oct 2011 4:05 AM #8
Solution!
Solution!
I've found a solution!
Jayrock is able to process GET requests. I stumbled about at http://groups.google.com/group/jayro...39d07a7635cc51 where Atif Aziz links to a good documentation of Jayrock: http://json-rpc.org/wd/JSON-RPC-1-1-...tProcedureCall
Just a few things to change on the project files:
1. Change on serverside the .NET [JsonRpcMethod("myJayrockNETMethod")] to [JsonRpcMethod("myJayrockNETMethod", Idempotent = true)] to enable GET requests and let jayrock handle the passing parameters.
2. Change your store's proxy 'url:' to '/path/to/yourHandler.ashx/myJayrockNETMethod' to let Ext know, thtt there is the location to pass parameters to.
3. Also change in the proxy config the 'extraParams:' (only if your 'myJayrockNETMethod' needs parameters), just assign in simple "key": "value" notation, like:
Ext will encode the parameters to something like '/path/to/yourHandler.ashx/myJayrockNETMethod?user=peter&site=marketplace'Code:[...] extraParams: { "user": "peter", "site": "marketplace" } [...]
If there are some special chars in the string, they will be encoded. Also a good place to experiment with url-encodings: http://www.albionresearch.com/misc/urlencode.php
Greetings, silent


Reply With Quote