【问题标题】:axios doesn't work on Samsung Tizen TVs but works fine in emulatoraxios 不适用于三星 Tizen 电视,但在模拟器中运行良好
【发布时间】:2018-07-28 10:06:28
【问题描述】:

simple axios 在模拟器和浏览器中运行良好,但在 Samsung Tizen TV 2016 上无法运行,并且在控制台中没有错误。

使用cdn:

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

和这样的脚本:

<!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>

【问题讨论】:

标签: javascript axios tizen samsung-smart-tv tizen-web-app


【解决方案1】:

解决了。在使用 axios 之前,必须在我们的脚本中添加一行代码:

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

【讨论】:

    【解决方案2】:

    您需要在config.xml中设置权限和访问策略

    特权

    为了授予访问网络的权限,您需要在 tizen studio 中进行设置。

    <tizen:privilege name="http://developer.samsung.com/privilege/network.public"/>
    

    政策

    您需要设置可以访问的网址。

    <access origin="*" subdomains="true"/>
    

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多