Skip to main content
added 1 character in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Is there a better way to read json Populating an unordered list from values in nodea JSON file

I have this view that populates an unordered list from values in a jsonJSON file., which I am doing this in nodeNode. So is

Is there a better way to do this, or a modemore 'node-like' way? Can I load the jsonJSON file without an ajaxAjax call?

<!DOCTYPE html>
<html>
<head>
    <title>4&middot;pli -- news</title>
    <link rel='stylesheet' href='/stylesheets/style.css'/>
    <script src="/javascripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/javascripts/date.format.js" type="text/javascript"></script>
    <link href='http://fonts.googleapis.com/css?family=Didact+Gothic' rel='stylesheet' type='text/css'>
</head>
<body>
<% include shared/nav.ejs %>
<div class="wrapper">
    <ul class='news'>
       <script type="text/javascript">
           $.ajax({
               url: 'data/news.json',
               async: false,
               dataType: 'json',
               success: function (response) {
                   var items = [];
                   $.each(response.news,function(i,item){
                       items.push('<li><ul><li class="title">'+ item.title +'</li><li>' + dateFormat(item.created_at,"fullDate") + '</li><li><p>'+ item.content +'</p></li></ul></li>');
                   });
                   $('.news').append(items.join(''));
               }
           });
       </script>
    </ul>

</div>
<% include /shared/footer.ejs %>
</body>
</html>

Is there a better way to read json in node

I have this view that populates an unordered list from values in a json file. I am doing this in node. So is there a better way to do this, or a mode 'node-like' way? Can I load the json file without an ajax call?

<!DOCTYPE html>
<html>
<head>
    <title>4&middot;pli -- news</title>
    <link rel='stylesheet' href='/stylesheets/style.css'/>
    <script src="/javascripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/javascripts/date.format.js" type="text/javascript"></script>
    <link href='http://fonts.googleapis.com/css?family=Didact+Gothic' rel='stylesheet' type='text/css'>
</head>
<body>
<% include shared/nav.ejs %>
<div class="wrapper">
    <ul class='news'>
       <script type="text/javascript">
           $.ajax({
               url: 'data/news.json',
               async: false,
               dataType: 'json',
               success: function (response) {
                   var items = [];
                   $.each(response.news,function(i,item){
                       items.push('<li><ul><li class="title">'+ item.title +'</li><li>' + dateFormat(item.created_at,"fullDate") + '</li><li><p>'+ item.content +'</p></li></ul></li>');
                   });
                   $('.news').append(items.join(''));
               }
           });
       </script>
    </ul>

</div>
<% include /shared/footer.ejs %>
</body>
</html>

Populating an unordered list from values in a JSON file

I have this view that populates an unordered list from values in a JSON file, which I am doing in Node.

Is there a better way to do this, or a more 'node-like' way? Can I load the JSON file without an Ajax call?

<!DOCTYPE html>
<html>
<head>
    <title>4&middot;pli -- news</title>
    <link rel='stylesheet' href='/stylesheets/style.css'/>
    <script src="/javascripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/javascripts/date.format.js" type="text/javascript"></script>
    <link href='http://fonts.googleapis.com/css?family=Didact+Gothic' rel='stylesheet' type='text/css'>
</head>
<body>
<% include shared/nav.ejs %>
<div class="wrapper">
    <ul class='news'>
       <script type="text/javascript">
           $.ajax({
               url: 'data/news.json',
               async: false,
               dataType: 'json',
               success: function (response) {
                   var items = [];
                   $.each(response.news,function(i,item){
                       items.push('<li><ul><li class="title">'+ item.title +'</li><li>' + dateFormat(item.created_at,"fullDate") + '</li><li><p>'+ item.content +'</p></li></ul></li>');
                   });
                   $('.news').append(items.join(''));
               }
           });
       </script>
    </ul>

</div>
<% include /shared/footer.ejs %>
</body>
</html>
Source Link
Antarr Byrd
  • 693
  • 2
  • 5
  • 16

Is there a better way to read json in node

I have this view that populates an unordered list from values in a json file. I am doing this in node. So is there a better way to do this, or a mode 'node-like' way? Can I load the json file without an ajax call?

<!DOCTYPE html>
<html>
<head>
    <title>4&middot;pli -- news</title>
    <link rel='stylesheet' href='/stylesheets/style.css'/>
    <script src="/javascripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/javascripts/date.format.js" type="text/javascript"></script>
    <link href='http://fonts.googleapis.com/css?family=Didact+Gothic' rel='stylesheet' type='text/css'>
</head>
<body>
<% include shared/nav.ejs %>
<div class="wrapper">
    <ul class='news'>
       <script type="text/javascript">
           $.ajax({
               url: 'data/news.json',
               async: false,
               dataType: 'json',
               success: function (response) {
                   var items = [];
                   $.each(response.news,function(i,item){
                       items.push('<li><ul><li class="title">'+ item.title +'</li><li>' + dateFormat(item.created_at,"fullDate") + '</li><li><p>'+ item.content +'</p></li></ul></li>');
                   });
                   $('.news').append(items.join(''));
               }
           });
       </script>
    </ul>

</div>
<% include /shared/footer.ejs %>
</body>
</html>