jQuery simple getJSON doesn't work
I want to load a simple json file and display it's content but it doesn't
work, I don't know why :(
Nothing is displayed on console.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('/api/?core=users&function=getJson', function(data) {
var items = [];
console.log("ok!");
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
});
</script>
</head>
<body>
<ul class="my-new-list">
<li>test</li>
</ul>
</body>
</html>
JSON datas loaded are :
{"fruit_name":"Tomato"}
Do you have an idea ?
Thank you !
No comments:
Post a Comment