Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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 JSON日期未显示在HTML中_Javascript_Html_Json - Fatal编程技术网

Javascript JSON日期未显示在HTML中

Javascript JSON日期未显示在HTML中,javascript,html,json,Javascript,Html,Json,我对JSON数据有一个问题:我想通过JSON URL制作新闻提要,但信息没有显示在HTML中 $function{ var分录=[]; var dmJSON=http://www.stellarbiotechnologies.com/media/press-releases/json; $.getJSON dmJSON,functiondata{ var html='${title}'; html+=; html+=''; html+='${monthName}'; html+='${day}

我对JSON数据有一个问题:我想通过JSON URL制作新闻提要,但信息没有显示在HTML中

$function{ var分录=[]; var dmJSON=http://www.stellarbiotechnologies.com/media/press-releases/json; $.getJSON dmJSON,functiondata{ var html='${title}'; html+=; html+=''; html+='${monthName}'; html+='${day}'; html+='${year}'; $'ticker'.html },
你可以这样做:

<script>
 $(document).ready(function() {

    var dmJSON = "http://www.stellarbiotechnologies.com/media/press-releases/json";
    $.getJSON( dmJSON, function(data) {

          var html = '';

            // loop through all the news items, and append the 
            // title and published date to the html variable.

            for(var i = 0; i < data.news.length; i++){

                html += '<div>';
                html += data.news[i].title 
                html += '<br>';
                html += data.news[i].published 
                html += '</div>';
            }

            // append all the html variable to the ticker div.
            $("#ticker").append(html);
        });

 });
</script>

这将在news节点中循环,获取标题和发布日期,然后将它们附加到页面中一个id为ticker的元素。

${title}?${published}?您正在使用某种模板库吗?$'ticker'.html…然后呢?您正在将所有内容附加到html变量中,但没有实际使用它。可能您需要$'ticker'.htmlhtml,而您没有实际循环返回的数据。感谢您的回复,${title}insiad json,事实上我不知道如何编程,我只需要一个他能修改代码的人。谢谢你,他工作得很好:一个爱的男人