0

Can anyone help me fetch data from https://dexonline.ro/definitie/skate?format=json. I tried fetch/ajax like this, but i'm getting this error:

enter image description here

With postman it works... Also i'm bad at English so just write the code, thanks in advance

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • Possible duplicate of [Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-origin-header-is-present) – msanford Sep 28 '17 at 21:35
  • no, we can't help you break the rules of every browser. you have to use your own server to "proxy" the data to your domain or with CORS – dandavis Sep 28 '17 at 21:40
  • Use `fetch('https://cors-anywhere.herokuapp.com/https://dexonline.ro/definitie/skate?format=json')` instead (that is, prefix the request URL with `https://cors-anywhere.herokuapp.com/`) — and for an explanation of what that does, see the *How to use a CORS proxy to get around “No Access-Control-Allow-Origin header” problems* section of the answer at https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141#43881141 – sideshowbarker Sep 28 '17 at 21:46
  • @Alex Jidras you got a solution on PHP using curl but or simple file_get_conent can save your life :). gl for the next, regards. –  Sep 28 '17 at 22:22

1 Answers1

0

Hi i guess you solve your problem, so i gave you the way on how to get this restriction out. Create a simple file PHP and copy/paste, i do file_get_contents you take the json and then you parse to a var javascript and you are done, regards ;).

 <?php
   $json = file_get_contents("https://dexonline.ro/definitie/skate?format=json");
?>
<!DOCTYPE html>
<html>
<head>
    <title>test</title>
</head>
<body>
<script>
    var json = <?php echo $json; ?>;
    document.body.onload = function(){
        document.write(json.word);//return Skate
    };
</script>
</body>
</html>

Regards.