[CLOSED] Adding params as jsonData for jsin Ajax requests

  1. #1

    [CLOSED] Adding params as jsonData for jsin Ajax requests

    I have hit into a major issue here. I make numerous Web Service json requests with method=POST. I thought that POST being the method, the params would be sent in the request body, and would NOt be appended to the Url. However, I just found that even for POST requests, the params are appended to the Url for json requests.

    Digging deep into the code, I found the following in Ext.net.DirectEvent.beforerequest listener:


                        if (o.cleanRequest) {
                            o.params = Ext.apply({}, o.extraParams || {});
    
    
                            for (var key in o.params) {
                                var ov = o.params[key];
    
    
                                if (typeof ov == "object") {
                                    o.params[key] = Ext.encode(ov);
                                }
                            }
    
    
                            if (o.json) {
                                o.jsonData = o.params;
                            }
                        }

    And according to Ext.Ajax.request docs,
    jsonData : Object/String (Optional)<div class="sub-desc" style="margin-top: 5px; margin-right: 5px; margin-bottom: 5px; margin-left: 16px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">JSON data to use as the post. Note: This will be used instead of params for the post data. Any params will be appended to the URL.

    My immediate concern is when I have specified POST as the request method, why then the data is being sent in the Url?? Why does Ext.net encodes it into jsinData making ExtJs append it into the url??


    I have checked that .asmx WebService methods can pick their arguments from POST data also. So, what is the reason for forcing data to be sent through url for json requests??
  2. #2

    RE: [CLOSED] Adding params as jsonData for jsin Ajax requests

    The reason that this is a major issue is because my parameters have large data larger than what can be accommodated in the url!!
  3. #3

    RE: [CLOSED] Adding params as jsonData for jsin Ajax requests

    Hi,

    It is our bug. We duplicates json data as params
    Fixed in SVN. Please update from SVN and retest
  4. #4

    RE: [CLOSED] Adding params as jsonData for jsin Ajax requests

    Hi vlad, just updated from SVN and compared to the original version. Here are my findings.

    This is the code from beforerequest listener in DirectEvent.js:


                            if (o.json) {
                                o.jsonData = o.params;
                            }

    Thus if I set json to true, the code automatically creates the jsinData property on the config object.


    Now, here's the code from the ExtJs Ajax class defined in Connection.js (line 284-287):


                    if((method == GET || o.xmlData || o.jsonData) &amp;&amp; p){
                        url = Ext.urlAppend(url, p);
                        p = '';
                    }

    Clearly, if jsinData is set on the config object, it would be appended to the url &amp; the params are emptied out. Although I have not yet tested the updated code, these findings should be reason enough to believe that it would not make any difference to the overall behavior, and the params would still be appended to the url.
  5. #5

    RE: [CLOSED] Adding params as jsonData for jsin Ajax requests

    Hi,

    No, please note that additional parameters are added to the url ('p' in the source code, jsonData is not added)
    Just previosly we create jsonData from parameters (o.params) and did not clear parameters. Therefore we had jsonData and parameters. Just o.params was url encoded


    Now we clear params if use json data
  6. #6

    RE: [CLOSED] Adding params as jsonData for jsin Ajax requests

    I again have a code breaking down here. As previously, data was sent in the Url, it was available through Request property on the server. However, the data is now sent in the POST body only. Here's a sample request (captured from Fiddler):

    POST /mysite.com/JsonWebService/getBranchVatDetail HTTP/1.1
    Accept: */*
    Accept-Language: en-US
    x-requested-with: XMLHttpRequest
    x-ext.net: delta=true
    Content-Type: application/json
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; FDM; InfoPath.2)
    Content-Length: 31
    Connection: Keep-Alive
    Pragma: no-cache


    {"branchNo":"2","vatCode":"XX"}


    This data is now available only if the WebService method signature is


    getBranchVatDetail(int, string)


    In some of my web service method calls, I pass a variable number of arguments. Therefore, the existing code accepts no parameter but access them through Context.Request["paramName"].


    This code has broken down now. Is there a way to either: Get the POST body url-encoded for a json request?


    This would allow me to access params through the Request object.

  7. #7

    RE: [CLOSED] Adding params as jsonData for jsin Ajax requests

    Okay, I removed json=true, and the parameters are now Url encoded.

    But now the response is handed over to my code as xml (and not json data). I think I am confused here a bit. My web service is marked as ScriptService &amp; the method as ScriptMethod.


    I would like to confirm that that if I passed json=true, it was ExtJs/Ext.net framework that parsed out the server Xml response into json. Am I correct here??
  8. #8

    RE: [CLOSED] Adding params as jsonData for jsin Ajax requests

    Hi,

    I am bit confuse with you requests. In the first post there was requirement if you use POST then need exclude url encoding (and it is correct) and in the POST only


    In the last post there is reverse requirement (pass params with url)


    I would like to confirm that that if I passed json=true, it was ExtJs/Ext.net framework that parsed out the server Xml response into json. Am I correct here??

    No, just webservice return pure json response. If you set json="true" then ExtJS adds header to the request :
    Content-Type : "application/json"


    Web service read that header, analyze posted content (it should be json) and return json response (if content type is "application/json"). Also as I know GET json request is not allowed (web service raises exception, you will get 500 http respopnse)


    Summary:


    - Place params which should passed in the POST body to the 'jsonData'
    - Place params which should url encoded to the 'params'
    - Remove 'json:true' (ExtJS automatically makes request as json if jsonData is presented)




    var jsonServicce = function (name) {
                Ext.net.DirectMethod.request({
                    url          : "JsonService.asmx/SayHello",
                    cleanRequest : true,
                    params       : {
                        name : name
                    },
                    jsonData       : {
                        name : name
                    },
                    success : function (result) {
                        Ext.Msg.alert("Json Message", result);
                    }
                });
            };

Similar Threads

  1. [OPEN] [#129] Can Ajax requests send If-Modified-Since headers
    By anup in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Jan 18, 2013, 4:26 AM
  2. Replies: 5
    Last Post: Jul 25, 2011, 6:14 PM
  3. Replies: 10
    Last Post: May 25, 2010, 5:11 PM
  4. Replies: 0
    Last Post: Jul 22, 2009, 4:40 AM
  5. Replies: 2
    Last Post: Jun 30, 2009, 4:03 PM

Posting Permissions