Welcome to Qi-U Community for programmer and developer-Open, Learning and Share

Categories

0 votes
402 views
in Technique[技术] by (31.9m points)

artTemplate Ajax json 渲染 得到api数据后 这样为什么不显示?

<link rel="stylesheet" href="../bfq/APlayer.min.css">
<script src="../bfq/APlayer.min.js"></script>
</head>
<body>

<div class="mui-table-view" id="newsinfo"></div>

<script id="lists" type="text/html">

//这个是播放器代码不显示~

<div id="aplayer"></div>
<script>
const ap = new APlayer({

  container: document.getElementById('aplayer'),
  audio: [{
      name: 'name',
      artist: 'artist',
      url: '{{@mp3}}',
      cover: 'cover.jpg'
  }]

});
</script>

</script>

    <script src="../js/template-web.js" type="text/javascript" charset="UTF-8"></script>
    <script type="text/javascript">
        mui.init();
        //添加newId自定义事件监听
        window.addEventListener('id', function(event) {
            //获得事件参数
            var id = event.detail.id;
            //根据id向服务器请求新闻详情    
        //plusReady,用来定义加载dom后的操作
        mui.plusReady(function() {
            
            mui.ajax('https://网址.com/'+ id, {
                /* data 是参数,我们这里不需要,我们只是从 api获取数据
                data: {
                    username: 'username',
                    password: 'password'
                },
                */
                escape: false,
                dataType: 'json', //服务器返回json格式数据
                type: 'get', //HTTP请求类型
                timeout: 10000, //超时时间设置为10秒;
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {                
                    //我们现在控制台打印一下请求结果
                    console.log(data);   
                    //然后获取json数据中的具体值
                    //console.log(data.stories[0].title)            
                    
                    var html = template('lists', data);
                   
                    document.getElementById("newsinfo").innerHTML = html;
                    console.log(html);
                },
                
                error: function(xhr, type, errorThrown) {
                    //异常处理;
                    console.log(type);
                }
            });
        });
        });            
    </script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (31.9m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Qi-U Community for programmer and developer-Open, Learning and Share
...