I\'m writing a simple site that takes as input an idiom, and return its meaning(s) and example(s) from Oxford Dictionary. Here\'s my idea:
I send a request to the fol
Is your website also on the oxfordlearnersdictionaries.com domain? or your trying to make a call to a domain and the same origin policy is blocking you?
Unless you have permission to set header via CORS on the oxfordlearnersdictionaries.com domain you may want to look for another approach.
If your website also on the oxfordlearnersdictionaries.com domain, USE the following into the oxfordlearnersdictionaries.com .htaccess file:
Header set Access-Control-Allow-Origin "*"
I think setting your header to Access-Control-Allow-Origin: *
would do the trick here. Had the same issue and I resolved it like that.
JSONP or "JSON with padding" is a communication technique used in JavaScript programs running in web browsers to request data from a server in a different domain, something prohibited by typical web browsers because of the same-origin policy. JSONP takes advantage of the fact that browsers do not enforce the same-origin policy on script tags. Note that for JSONP to work, a server must know how to reply with JSONP-formatted results. JSONP does not work with JSON-formatted results.
http://en.wikipedia.org/wiki/JSONP
Good answer on stackoverflow: jQuery AJAX cross domain
$.ajax({
type: "GET",
url: 'http://www.oxfordlearnersdictionaries.com/search/english/direct/',
data:{q:idiom},
async:true,
dataType : 'jsonp', //you may use jsonp for cross origin request
crossDomain:true,
success: function(data, status, xhr) {
alert(xhr.getResponseHeader('Location'));
}
});
I had the same problem when I was working on asp.net Mvc webApi because cors was not enabled. I solved this by enabling cors inside register method of webApiconfig
First install cors from here then
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
config.EnableCors();
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Add the below code to your .htaccess
Header set Access-Control-Allow-Origin *
It works for me.
Thanks