首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用JS获取内容,用PHP回显

用JS获取内容,用PHP回显
EN

Stack Overflow用户
提问于 2019-03-08 20:08:12
回答 1查看 157关注 0票数 0

我不熟悉js。我想要得到"file_get_contents“函数的结果,并将其放在”源“上(我已经用.标记了两者)。

提前谢谢你。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-08 23:35:34

我认为如果你使用下面的代码,你会更接近你的解决方案。

代码语言:javascript
复制
<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>

如果你告诉我console.dir的输出是什么,我也许能提供更多帮助。

顺便说一句,clapper不是有一些文档展示了如何使用它的API吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55062942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档