JSON文件:
{
"name": "select2",
"title": "Select2",
"version": "3.4.2",
"author": {
"name": "Igor Vaynberg",
"url": "https://github.com/ivaynberg"
}
}
HTML文件:
<html>
<body>
<a href="data.json" target="_blank">Open JSON file</a><br />
<input type="button" value="Get and parse JSON" class="button" />
<br />
<span id="results"></span>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.button').click(function () {
$.ajax({
url: "data.json",
dataType: "text",
success: function (data) {
var json = $.parseJSON(data);
$('#results').html('Plugin name: ' + json.name + '<br />Author: ' + json.author.name);
}
});
});
});
</script>
</body>
</html>
是否要对跨浏览器脚本问题做些什么?我无法显示JSON文件的任何字段。这两个文件都存储在同一目录级别中。