I am trying to fetch this json object from this url:
https://test3.diavgeia.gov.gr/luminapi/opendata/dictionaries//KANONISTIKI_PRAXI_TYPE.json
You might not
Your internet browser is blocking CORS Ajax calls. As a workaround one option is to deploy your own web application just for running web requests to target diavgeia.gov.gr
external web api without this restriction.
Internet browser -(Ajax) -> Your web server -> Target web site
Another option is using reverse proxy websites that already provide this service for free. They will call the external web api for you from a server, not an Internet browser, so that CORS can be avoided.
Internet browser -(Ajax) -> Reverse proxy -> Target web site
let anonimizerUrl = 'https://allorigins.us';
var apiUrl = 'https://test3.diavgeia.gov.gr/luminapi/opendata/dictionaries/KANONISTIKI_PRAXI_TYPE.json';
$.ajax({
url: anonimizerUrl + '/get?url=' + encodeURIComponent(apiUrl),
success: function(response) {
//Although response is an object, the field contents is a string and needs to be parsed here.
var data = JSON.parse(response.contents);
console.log(data);
},
error: function(request) {
console.log(request.responseText);
}
});
If Allorigins
is blocked by your internet provider (ISP), try another similar server from this list including.
Note: Based on your post, I'm assuming you don't have access to make changes to the web api. Otherwise CORS can be enable from there or make changes for returning jsonp instead of json.