Making a JSONP Call to a WCF Data Service using datajs
During MIX11 I attended a very interesting session about datajs which was presented by Asad Khan and Marcelo Lopez Ruiz. As I promised in my previous post, in this post I’ll show you how to make a JSONP call to a WCF Data Service using datajs library.
A Little About datajs
Making JSONP Call using datajs
Here is the implementation of the same JSONP call functionality from the previous post but using datajs:
A few things to notice in the example:
- I add the script to datajs which exists in my web application project under the Scripts directory.
- You need to enable JSONP through the OData.defaultHttpClient.enableJsonpCallback which is disabled by default.
- Use the OData.Read function to make the call to the service (no need to add the format or callback query parameters like I did in the previous post since they are added automatically).
Pay attention that in a real world application you would probably like to disable JsonpCallback after you make the call.
datajs is still in Alpha version and it is only in its starting point. It tries to provide a common solution around the data problem in the client side development. I expect it to grow and to supply more capabilities in the future. In this post I showed how to use it in order to make a JSONP call to a JSONP enabled WCF Data Service.