1. 数据data.json 和test.html ,与jquery-3.0.0.min.j在同一路径下
2.
3. Test.html代码(jquery异步获取json代码方式)
<html>
<head>
<title>
</title>
</head>
<body>
hi
</body>
<scriptsrc="js/jquery-3.0.0.min.js"></script>
<scripttype="text/javascript">
$(function() {
$.getJSON('data.json', function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val +'</li>');
});
$('<ul/>', {
'class': 'list',
html: items.join('')
}).appendTo('body');
});
});
</script>
</html>
4. data.json
{
"one" : "Hello",
"two" : "World"
}