ERROR: Request is not local and cannot be done through JSONP

Sep 19, 2012 at 6:09 PM
Edited Sep 20, 2012 at 4:37 AM

Hi,

I developed a HTML page to send requests to an OData endpoint, and I used datajs to send requests using OData class. 
I'm trying to send a POST,PUT, or DELETE to an OData endpoint that is another server and I get the error:  "Request is not local and cannot be done through JSONP".

If the OData is in the same server that the htm page, everything works perfectly.

The endpoint uses basic authentication. Also, GET request works perfectly.

var request = {
requestUri: url, method: httpMethod, user: user, password: password,
data: jsonEntity, jsonpCallback:
'myCallback', dataType: 'jsonp'}

OData.request ( request,
function success(data, result) {...},
function error(err) {...});

Using a HTML page, is possible to send a POST request to an OData endpoint in any server ?

Thanks!

 

Sep 24, 2012 at 6:36 PM

Hi Christian,

JSONP is a very limited tool for doing cross domain requests and avoid the browser's same origin policy.  Unfortunately, given how it works (by injecting script tags into the page DOM), it can only be used for non authenticated GET requests. 

You will need to use other tools for your particular scenario (sending cross domain POSTS), like CORS (just recently becoming popular, but needs to be supported both by the endpoint and the browsers) or a reverse proxy (a dummy service in the page domain that relays the request to the real endpoint in the other domain).  I would suggest you a reverse proxy given that for the time being is the most robust solution for your scenario.

Regards,

Alex Trigo.