markitondemand / DEPRECATED-DataApis

Markit On Demand - Market Data APIs
http://dev.markitondemand.com
MIT License
178 stars 68 forks source link

Cross Origin Request Blocked Error #17

Closed swaroopjo closed 9 years ago

swaroopjo commented 9 years ago

I have been developing a test application using angular JS but getting this error on Chrome and Firefox. Internet explorer seems to work fine though. I looked at some blogs tried to modify the Http headers from the client side but no luck.

Here is the full error from firefox : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://dev.markitondemand.com/Api/v2/Lookup/json?input=G. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

markhealey commented 9 years ago

Hi @swaroopjo, please see #9 for the details on this API and CORS.

ETNOL commented 9 years ago

One way of solving this would be to ask for jsonp returns. If you're using the convenient jQuery ajax method you can just change the dataType:"json" to dataType:"jsonp" and your request url to the following:

http://dev.markitondemand.com/Api/v2/Lookup/jsonp?input=G

markhealey commented 9 years ago

:+1: what @ETNOL said

swaroopjo commented 9 years ago

Thank you all. This works with JsonP. I am still using angularJS though. Here's what i have done.

var JSON_CALLBACK = function(response){
  console.log("Callback function called");
  //showResult(response)
};

$http.jsonp("http://dev.markitondemand.com/Api/v2/Lookup/jsonp?input=G&&callback=JSON_CALLBACK")
.success(function(response){
    console.log("Data Received: "+response);
    showResult(response)
})
.error(function(){
    console.log("Error Occured !!.");
});
markhealey commented 9 years ago

Nice @swaroopjo, thanks for updating us