简单的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>
答案 0 :(得分:1)
解决了。在使用axios之前,必须在脚本中添加一行代码:
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
答案 1 :(得分:0)