OGDI and datajs

Jun 1, 2011 at 3:04 AM


Myself and Nik Garusha (@nik_g) are trying to do some stuff with OGDI based services. But we are facing problem when using it with datajs. Please go thro the following and let us know where we are going wrong:

The service we are trying to access is : http://datadotgcds2.cloudapp.net/v1/Hack%20OpenData/CouncilExpenseData

Since OGDI doesnt support $skip, we cannot use dataja cache. We first wrote a Jquery Ajax request as below:

var query = "http://datadotgcds2.cloudapp.net/v1/Hack OpenData/CouncilExpenseData/?&format=json" + "&$callback=SuccessCallback";
url: query,
success: SuccessCallback

this comes back with JSON result.

I tried to achieve the same with datajs. Here is the code:

OData.defaultHttpClient.enableJsonpCallback = true;
requestUri: "http://datadotgcds2.cloudapp.net/v1/Hack OpenData/CouncilExpenseData",
headers: { Accept: "application/json" }
function (data, response) {
alert("Operation succeeded.");
function (err) {
alert("Error occurred " + err.message);

i dont get success or error. When i do network capture the call to the service is 200. I use F12 and capture the network. so there what i have noticed is its not coming back with JSON instead it coming back with atom+xml ??

Any idea what i am doing wrong here ?

Jun 1, 2011 at 4:35 AM

The server is using 'format' rather than '$format' as the parameter name. This should do the trick for you.

OData.defaultHttpClient.formatQueryString = "format=json";

As an extra note, the headers values are ignored when we use JSONP - we send what we've got and try to deal with the result as best as we can - for read-only scenarios where JSONP is appropriate, there is no "error" in general by not including these values.

Jun 2, 2011 at 5:47 PM


Thanks for the tip. that did the trick. I am now able to get the OGDI service data. One more question i had is :

Using createDataCache we can cache all the data by setting the prefetch to -1. is there a way we can read till the end using the readRange ?? is this possible. Scenario is i want to cache using the createDataCache. and then read the whole lot.... any pointers on this.


Jun 2, 2011 at 8:02 PM

Right now, your best bet is to pass a "really really large" number for readRange count - that should get you everything. Do you really want everything in a big array like that though?

Another option that will be available in a near-future changeset; we've added ToObservable support, so if you're using RxJs, you can get async notification of the items as we download them (so you don't have to hold on to all of them at once).