Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 刷新div内容,其中包含一个脚本,该脚本将提要获取为document.write_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Javascript 刷新div内容,其中包含一个脚本,该脚本将提要获取为document.write

Javascript 刷新div内容,其中包含一个脚本,该脚本将提要获取为document.write,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我一直在尝试做一个网页,展示我每天使用的各种东西。我试着在那里获取一个Reddit提要,它会每x秒(60秒或其他)自动刷新一次。但问题是,feed是 document.write({INSERT FEED HERE}); 异步加载,因此会出现错误: Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external s

我一直在尝试做一个网页,展示我每天使用的各种东西。我试着在那里获取一个Reddit提要,它会每x秒(60秒或其他)自动刷新一次。但问题是,feed是

document.write({INSERT FEED HERE});
异步加载,因此会出现错误:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
那么,有没有什么方法可以在不更新整个页面的情况下,自行进行更新呢

<head>  
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>

<body>
<div id="reddit">
<script>
    $(document).ready(
        function() {
            setInterval(function() {
                reload_js();
            }, 60000);
        });

        function reload_js() {
        var s = document.createElement("script");
        s.type = "text/javascript";
        s.src = "https://www.reddit.com/r/ProgrammerHumor/new/.embed?limit=10&t=all";
        document.getElementById("reddit").appendChild(s);
    }
    </script>
</div>
</body>

$(文件)。准备好了吗(
函数(){
setInterval(函数(){
重新加载_js();
}, 60000);
});
函数重载_js(){
var s=document.createElement(“脚本”);
s、 type=“text/javascript”;
s、 src=”https://www.reddit.com/r/ProgrammerHumor/new/.embed?limit=10&t=all";
文件.getElementById(“reddit”).appendChild;
}

这是我现在为reddit提要提供的简单页面。

默认情况下,
.embed
webservice使用
文档。如果未定义回调参数,则编写

只需添加一个回调参数,如下所示

并添加一个将附加内容的
yourFunction
函数

function yourFunction(data) {
  document.getElementById("reddit").appendChild(data);
}

享受:)

默认情况下,
.embed
webservice使用
文档。如果未定义回调参数,则写入

只需添加一个回调参数,如下所示

并添加一个将附加内容的
yourFunction
函数

function yourFunction(data) {
  document.getElementById("reddit").appendChild(data);
}
享受:)