javascript - Display JSON data from url using ajax -
we want display names our json file div using javascript. tried lot of things, didn't manage succeed.
json data : http://www.smartbustracking.be/json/data.json
this tried :
<button>get data</button> <div id="resultjson"></div> <script type="text/javascript" language="javascript"> $("button").click(function(){ $.getjson("http://www.smartbustracking.be/json/data.json", function(result){ for(var x = 0; x < result.length; x++){ $.each(result, function(i, field) { $("#resultjson").append(field[x].name); } } }); });
if can ploblem, great
thanks in advance !
don't use loop inside loop extract name.
your data like
[0] = {name:"name1"} [1] = { name: "name2"}
if there array inside [0] , want extract value need loop inside loop extract value wanna pull value of bushaltes
.
try this
$("button").click(function() { $.getjson("http://www.smartbustracking.be/json/data.json", function(result) { console.log(result); (var x = 0; x < result.length; x++) { $("#resultjson").append(result[x].name); } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button>get data</button> <div id="resultjson"></div>
Comments
Post a Comment