BROWSER ISSUES

Sep 20, 2011 at 8:43 PM

I'm trying to do batch GETs (as well as POSTs and PUTs) using code similar to :

      OData.request({
                    requestUri: "http://xxx.yyy.com/zzz.svc/$batch",
                    method: "POST",
                    data: { __batchRequests: [
                         { requestUri: "Evaluations(customerId=1,evalID=3)", method: "GET" },
                         { requestUri: "Evaluations(customerId=1,evalID=4)", method: "GET" }
                      ]}
                }, function (data, response) {
                    alert(response);
                }, undefined, OData.batchHandler);
                OData.defaultError = function (err) {
                    alert("Error: " + err.message + " - " + err.response.body);
                };  });

The problem is that this request only returns data when viewing in IE8.  (I need to get this working in Chrome and Firefox.)
I am using the JSONP extension for WCF Data Services and have tried using OData.defaultHttpClient.enableJsonpCallback = true;.

Typically, I get a 200 return code with no data when trying to view in Chrome or Firefox.  Can somebody provide the correct syntax and/or browser settings for performing such a call?


Sep 22, 2011 at 12:42 AM
Edited Sep 22, 2011 at 11:32 PM

Hi ternst,

Hope you are doing great.  Batch requests aren't supported with JSONP because the technique only allows for HTTP GET requests.  Batch requests are sent to the endpoint as a multipart/mixed POST request, even if it consists only of GET requests.  The reason why IE can perform the request while other browsers don't is because of IE's implementation of XMLHttpRequest.  In IE, a cross domain request using XHR will cause the browser to promt the user for approval.  This is not the standard behavior; hence why the other browsers fail. 

I think the easiest solution would be not to use a batch request, but instead send the individual GET requests in a loop.  Also, you can use ATOM instead of JSONP, by using some sort of trick to workaround the browser's same origin policy... for example, you can use a simple odata service in your server that relays the request to the target service or you could take advantage of Silverlight's HTML bridge and a custom httpClient object that knows how to send the request through the bridge. 

Regards,

Alex Trigo.