0

Here is a snippet from my code:

<script>
$(document).ready(function(){
$.get('https://{URL}', function(data, status){
        list = JSON.parse(data);
        parseDocument(list)
        fct()
    })
});
</script>

<html>
<body>
<div class="headers">
<p> <b> Input Values: </b> </p>
<p> <b> Results </b> </p>
</div>
</body>
</html>

I need to print the data from get() next to Input Values: How do I do that?

  • 1
    In your HTML, add a span with an ID: ``, and in your JS, do `$('#mySpan').text(/* Your content */);` – blex Feb 05 '17 at 10:57

2 Answers2

0

You will need to put:

<script type="text/javascript"></script> 

In your head and not above your html. It's safer to place it in an external document: How do I hide javascript code in a webpage? and then <script type="text/javascript">document.write(list);</script>

Hope this helps.

Community
  • 1
  • 1
Anoniem
  • 75
  • 12
0

Could be something like this:

HTML

<html>
<head>
<script
    src="https://code.jquery.com/jquery-3.1.1.js"
    integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
    crossorigin="anonymous">    
</script>
</head>
    <body>
        <div class="headers">
            <p> <b> Input Values: </b> </p>
            <p id="results"> <b> Results </b> </p>
        </div>
    </body>
</html>

JS

<script>
$(document).ready(function(){
    var data = ["value1", "value2"];
    $("#results").append(data.join(", "));
});
</script>

Here's the pen: http://codepen.io/eduard-malakhov/pen/wgXqQV

Eduard Malakhov
  • 1,095
  • 4
  • 13
  • 25
  • Thanks for the answer! It gave me an idea, but I need to use something like this for JS $(document).ready(function(){ var data = $.get("URL") $("#results").append(data.join(", ")); }); as i do not know the input values, i need to retrieve them from an URL. But the example i gave here does not populate the #results. – Adrian Felea Feb 05 '17 at 11:10
  • @AdrianFelea but the rest you have already in your code. Your `list` is the data you want to fill in, isn't it? – Eduard Malakhov Feb 05 '17 at 11:35
  • yes that is i need to print in the html page next to "Input Values:" line. – Adrian Felea Feb 05 '17 at 11:40
  • thank you for all your replies, i figured it out. Now i just can't believe i didn't see it! – Adrian Felea Feb 05 '17 at 11:45