Reputation: 88
This is my Index.html
<div id="#here">
</div>
<script type="text/javascript">
$( document ).ready(function() {
$.getJSON("https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_ETH&depth=30", function(data){
var x = data.asks
$.each(x, function(index, item) {
//console.log(item);
$('#here').append("<p>"+ item +"</p>");
});
});
});
</script>
i'm just trying to parse a json an put inside a p
.
in the console the script runs ok
help guys, pleas
Upvotes: 3
Views: 50
Reputation: 15293
item
is an array so you need to access the array element using brackets notation like so:
item[0]
You also want to remove the #
symbol from the id
attribute of your div
element.
The id
attribute value must begin with a letter.
So this should work.
--HTML--
<div id="here"></div>
--JS--
$( document ).ready(function() {
$.getJSON("https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_ETH&depth=30", function(data) {
var x = data.asks;
$.each(x, function(index, item) {
var $paragraph = $('<p>');
$paragraph.text(item[0])
$('#here').append($paragraph);
});
});
});
Upvotes: 1