duanbai5348
duanbai5348
2019-03-08 12:08
浏览 48
已采纳

使用JS获取内容并使用PHP回显

I'm not familiar with js. I'd like to get the result of "file_get_contents" function and put it on the "source" (I have marked both with .................).

Thank you in advance.

<script>
var myInit = {
referrer: '',
};
function file_get_contents(filename) {
fetch(filename, myInit).then((resp) => resp.text()).then(function(data) {
    content = JSON.parse(data)
    fetch(content['some']['media']['content'], myInit).then((resp) => 
resp.text()).then(function(data));});}
file_get_contents("https://.................");
</script>

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/clappr@latest/dist/clappr.min.js"> 
</script>
</head>
<div id="player"></div>
<script>
    window.onload = function() {
        var player = new Clappr.Player({
            source: '<?php echo $url...................?>',
            parentId: "#player",
            height: '100%',
            width: '100%',
            autoPlay: true,
        });};
</script>
</body>
</html>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongwenghe2416
    dongwenghe2416 2019-03-08 15:35
    已采纳

    I think if you use the following code, you will get closer to your solution.

    <script>
    var myInit = {
    referrer: '',
    };
    function file_get_contents(filename) {
    fetch(filename, myInit).then((resp) => resp.text()).then(function(data) {
        var content = JSON.parse(data);
        console.dir(content);
        var player = new Clappr.Player({
                source: content['some']['media']['content'],
                parentId: "#player",
                height: '100%',
                width: '100%',
                autoPlay: true,
            });
        });
    }
    file_get_contents("https://.................");
    </script>
    
    <html>
    <head>
    <script src="https://cdn.jsdelivr.net/npm/clappr@latest/dist/clappr.min.js"> 
    </script>
    </head>
    <div id="player"></div>
    <script>
        window.onload = function() {
            //Whatever
        };
    </script>
    </body>
    </html>
    

    If you tell me what console.dir outputs, I might be able to offer more help.

    BTW.: doesn't clapper have some documents showing how to use its API?

    点赞 评论

相关推荐