如何从后端在前端显示数据?

时间:2019-05-31 19:47:20

标签: html

我正在尝试从后端获取数据,即使用ajax数据的node js已成功发送到前端,但未在前端显示。如何在新闻磁带即jquery插件的前端显示数据?

HTML代码:

<div class="panel-body">
  <div class="newstape">
    <div class="newstape-content">
      <div class="news-block" id="news">
      <h3 id="titl" name="title"></h3>
      <small id="date"></small>
      <p class="text-justify" id="dscrptn" name="description"></p>
      <hr />
      </div>
    </div>
  </div>
</div>


Script:

<script>
  $(document).ready(function() {
    $.ajax({
      url:"/news",
      contentType: 'application/json',
      success: function(res) {
        var news = document.getElementById('news');
        var html;
        res.forEach(function (data)  {
          news.innerHtml += "<h3 id='titl' name='titl'>" + data.title +"</h3>";
          news.innerHtml +=  "<small id='date' name='titl'>" + data.date +" </small>";
          news.innerHtml += "<p id='dscrptn' name='description'>"+ data.description + "</p>";
        });
        console.log(res);
      }
    });
  });
</script>

Data is not Showing at frontend.

0 个答案:

没有答案