Login Register

Help with JsonService. POST not happening.

Hi All

Would someone please help me with this? I am not receving POST data at the server side.

My function name is JSProxy and the only parameter I am passing to this is "methodName". Here's my SMD:

{
        "SMDVersion":".1",
        "objectName":"$",
        "serviceType":"JSON-RPC",
        "serviceURL":"sprytest.cfm",
        "methods":[
                {
                        "name":"JSProxy",
                        "parameters":[
                                {
                                        "name":"methodname",
                                        "type":"STRING"
                                }
                        ]
                }
        ]
}

I understand that this will use HTTP POST method. But I dont receive any POST data at the server side which is running ColdFusion.

I can see this in debug output at the client side:

DEBUG: JsonService: JSON-RPC Request: {"params":[{"methodName":"getContentTypes"}],"method":"JSProxy","id":1}

When it failed, I also tried modifying the createRequest function in src\rpc\JsonService.js to WDDXSerialize the data instead of dojo.json.serialize(req);. But the following debug log blowed my mind. Nothing beneath the "params" is de-serialized. Why? Is it a private variable which I cannot access. Whats happening?

DEBUG:  JsonService: JSON-RPC Request: <wddxPacket version='1.0'><header/><data><struct><var name='params'><struct></struct></var><var name='method'><string>JSProxy</string></var><var name='id'><number>1</number></var></struct></data></wddxPacket>

Can somebody tell me how read the data which dojo will pass to someXMLHTTPRequestObject.send() method??

Thanks.

-Sam

Answer/Solution - ColdFusion

In case someone is interested in this, I found a solution to my problem. ColdFusion server would ignore POST variables which are not encoded in a format it understands. And the good old CF understands "application/x-www-form-urlencoded".

If you are facing the same problem, where your server is not receiving POST data from dojo, then change the contentType to "application/x-www-form-urlencoded". You'll have to make this change in either JsonService.js or RpcService.js or both. Or as the case may be, in some other file which defines the contentType being posted. By default the content type in JsonService is text/json.

In addition, you'll have to make one change in createRequest function of your XxxxService.js. You'll have to prepend "token=" to the string that this function returns. Plus, you must use escape() function. Here's how return statement of createRequest() function must look like:

return "token=" + escape(data);
// "token" is just the name of the Form variable.... you can also use "message=" or "firstname="... change it as required

Whew, it took 6 days to figure this one out... but I'm happy I'd crack it. :)