Search code examples
javascriptaxiostizensamsung-smart-tvtizen-web-app

axios doesn't work on Samsung Tizen TVs but works fine in emulator


simple axios works fine in emulator and browsers but doesn't work on Samsung Tizen TV 2016 and there is no error in console.

with using cdn:

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

and script like this:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="Tizen basic template generated by Tizen Web IDE"/>

    <title>Tizen Web IDE - Tizen - Samsung Tizen TV basic Application</title>

    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <script src="js/main.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body style="width: 1920px; height:1080px; position: fixed;">

  <script>  
      axios.get('https://api.github.com/users/axios')
      .then(function(response){
      console.log(response.data);
      id = response.data.id;
      alert(id);
      });
  </script>
</body>
</html>

Solution

  • solved. there's a line of code that must be added to our script before using axios:

    axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';