我真的有些莫名其妙:
我在一个名为的文件中有以下 JSON 数据:data.json
{
"locations": [
{
"title": "The Space Needle",
"latitude": 47.619,
"longitude": -122.348
},
{
"title": "Albany",
"latitude": 46,
"longitude": -74
}
]
}
当我使用以下代码尝试显示数据时,我什么也得不到:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Another gone south</title>
<script src="http://code.jquery.com/jquery-1.8.0.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){
$.getJSON("data.json",function(data){
$.each(data.locations, function(i,location){
content += '<p>' + location.title + '</p>';
content += '<p>' + location.latitude + '</p>';
content += '<p' + location.longitude + '</p>';
content += '<br/>';
alert('aler called');
$(content).appendTo("#loc");
});
});
});
/* ]]> */
</script>
</head>
<body>
<div class="container">
<div class="span-24">
<h2>Check out the following locations:</h2>
<div id="loc">
</div>
</div>
</div>
</body>
</html>