1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    Karlsruhe, Germany
    Posts
    21
    Answers
    2
    Vote Rating
    0
    silent is on a distinguished road

      0  

    Question 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!

  2. 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:
    Code:
    [...]
    extraParams: {
        "user": "peter",
        "site": "marketplace"
    }
    [...]
    Ext will encode the parameters to something like '/path/to/yourHandler.ashx/myJayrockNETMethod?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

  3. #2
    Sencha User
    Join Date
    Feb 2011
    Posts
    174
    Answers
    10
    Vote Rating
    1
    netemp is on a distinguished road

      0  

    Default


    Quote Originally Posted by silent View Post
    Is there a possibility to add custom data like JSON encoded strings to the server?
    If I understand you correctly, then you want to pass a JSON string like - {key1:value1, key2:value2} - to the server?

    If yes, then how about giving this a try:

    Code:
    extraParams:{
      jsonStr:{key1:value1, key2:value2}
    }

  4. #3
    Sencha User
    Join Date
    Oct 2011
    Location
    Karlsruhe, Germany
    Posts
    21
    Answers
    2
    Vote Rating
    0
    silent is on a distinguished road

      0  

    Default


    Quote Originally Posted by netemp View Post
    If I understand you correctly, then you want to pass a JSON string like - {key1:value1, key2:value2} - to the server?

    If yes, then how about giving this a try:

    Code:
    extraParams:{
      jsonStr:{key1:value1, key2:value2}
    }
    That doesn't work. Can I use the writer config to send data with type 'json' - just that the Proxy encodes my data in JSON?

  5. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    174
    Answers
    10
    Vote Rating
    1
    netemp is on a distinguished road

      0  

    Default


    Quote Originally Posted by silent View Post
    That doesn't work. Can I use the writer config to send data with type 'json' - just that the Proxy encodes my data in JSON?
    This has been working fine for me so far. I missed adding the quotes around the JSON string as following:

    Code:
    extraParams:{
      jsonStr:'{key1:value1, key2:value2}'
    }
    This should resolve the issue.

  6. #5
    Sencha User
    Join Date
    Oct 2011
    Location
    Karlsruhe, Germany
    Posts
    21
    Answers
    2
    Vote Rating
    0
    silent is on a distinguished road

      0  

    Default


    Quote Originally Posted by netemp View Post
    This has been working fine for me so far. I missed adding the quotes around the JSON string as following:

    Code:
    extraParams:{
      jsonStr:'{key1:value1, key2:value2}'
    }
    This should resolve the issue.
    This will only name the Parameter jsonStr and assign them the value of a pseudo-json object and url encoded, that's bad. and not what I want, because my backend only accepts full JSON objects, nothing else.

    Is there another solution to work with this?

  7. #6
    Sencha User
    Join Date
    Feb 2011
    Posts
    174
    Answers
    10
    Vote Rating
    1
    netemp is on a distinguished road

      0  

    Default


    Quote Originally Posted by silent View Post
    This will only name the Parameter jsonStr and assign them the value of a pseudo-json object and url encoded, that's bad. and not what I want, because my backend only accepts full JSON objects, nothing else.

    Is there another solution to work with this?
    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


  8. #7
    Sencha User
    Join Date
    Oct 2011
    Location
    Karlsruhe, Germany
    Posts
    21
    Answers
    2
    Vote Rating
    0
    silent is on a distinguished road

      0  

    Default


    Quote Originally Posted by netemp View Post
    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

    I'm using Jayrock on a .NET backend. The problem here is, that Jayrock first gets the data from the request and I can't manually decode it. So I need a proper way to insert that, If there's no solution I must write my own proxy class.

  9. #8
    Sencha User
    Join Date
    Oct 2011
    Location
    Karlsruhe, Germany
    Posts
    21
    Answers
    2
    Vote Rating
    0
    silent is on a distinguished road

      0  

    Thumbs up 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:
    Code:
    [...]
    extraParams: {
        "user": "peter",
        "site": "marketplace"
    }
    [...]
    Ext will encode the parameters to something like '/path/to/yourHandler.ashx/myJayrockNETMethod?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

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar