Wednesday 17 May 2017

Loop text not getting printed inside html

I have a webpage in which I want to display the articles headlines that I am fetching from NewYork Time API, I am using nodejs as well, but the problem is that my articles gets printed below the end of html, although it should be printed inside like the "SAMPLE TEXT" is getting printed, is there a way in which I can print it inside?

                       <div class="card">
                            <div class="header">
                                <h3 class="title"><center><b>Chronicle</b></center></h3>
                            </div>
                            <body>
                                <p id="headline">SAMPLE TEXT</p>
                                <script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.9/p5.js"></script>
                                <script>
                                var url = "https://api.nytimes.com/svc/search/v2/articlesearch.json";
                                url += '?' + $.param({
                                    'api-key': "removed",
                                    'q': "Trump"
                                });
                                $.ajax({
                                    url: url,
                                    method: 'GET',
                                }).done(function(result) {
                                    var articles = result.response.docs;
                                    for (var i=0; i<articles.length;i++)
                                    {
                                        document.createElement('div');
                                        document.createElement("H1");
                                        var h = document.createElement("H1");
                                        var t = document.createTextNode(articles[i].headline.main);
                                        h.appendChild(t);
                                        document.body.appendChild(h);
                                    }

                                }).fail(function(err) {
                                    throw err;
                                });
                                </script>


                            </body>



via Titanz

No comments:

Post a Comment