简体   繁体   中英

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>

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'] = '*';

You need to set the privilege and the access policy in the config.xml

Privilege

In order give the permission to access the network you need to set it in the tizen studio.

在 tizen studio 中设置 Internet 权限

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

Policy

Hery you need set set which urls you can access. 在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM