Developers
Forum
Index >> OpenSocial >> Supporting OpenSocial AJAX API
#1 2009-10-23 18:11:46
- bjouhier

- Member
Do you have plans to support the OpenSocial AJAX API (gadgets.io.makeRequest)? If so, when?
I have a gadget that works with the gadgets.io.makeRequest API in various OpenSocial containers but I cannot make it work with UWA.Data.request.
My gadget needs to send an AJAX call that POSTs a piece of JSON and expects a JSON response. UWA.Data.request seems to assume that the posted data is URL-form-encoded. I want JSON instead and I don't see how I can specify this with UWA.Data.request (but I can do it with gadgets.io.makeRequest). The type property allows me to specify the response type but I also need to specify the request type so that I can post JSON. I suspect that people who want to do POST XML have a similar problem.
Do you have any example of POSTing XML or JSON with UWA.Data.request?
Bruno
Offline
#2 2009-10-27 12:30:11
- Xavier Borderie

- UWA support crew
There is no immediate plan to support gadgets.io.makeRequest .
You can use UWA.Data.request() to POST your JSON object. See this code:
Code:
UWA.Data.request(
'http://domain.name/json.php',
{
'method': 'post',
'type': 'text',
'proxy': 'ajax',
'onComplete': callbackFonction,
'postBody': '{"version" : "1.1", "method" : "test", "params" : [1, 2, 3, 4, 5]}',
'requestHeaders' : ['Content-Type', 'application/json']
});
}In order to POST XML data, the same solution should work, only with a different content-type.
Let us know how this works for you.
Offline
#3 2009-10-30 10:32:35
- bjouhier

- Member
Thanks Xavier, I managed to make it work.
BTW, I did not see the requestHeaders feature in the doc when I worked on this last week. I looked at it again today and saw it (in http://dev.netvibes.com/doc/uwa/documen … using_ajax). But it is still missing from the reference API page (http://netvibes.org/specs/uwa/current-w … hodrequest)
I also hit a problem with JSON encoding. I'll post it separately in the other forum as this is not OpenSocial related.
Bruno
Offline
#4 2009-10-30 17:04:39
- Xavier Borderie

- UWA support crew
Yes, I just update the /doc after your request.
The API page will take some time to get update, I'm afraid...
Offline
1
