我注意到许多调用返回 json 数据的 Web 服务的代码示例,但实现通常涉及 PHP 等后端语言。有谁知道所有 jQuery 解决方案的好方法?换句话说,例如使用 id 设置 div 标签,然后直接调用 Web 服务,获取 json 数据并填充页面?根本没有 PHP 或其他后端服务器端代码。
有些事情没有意义。这完美地工作:
<script type="text/javascript">
jQuery(document).ready(function ($) {
$.ajax({
url: "http://api.wunderground.com/api/ac7e64a2f6e2d440/geolookup/conditions/q/IA/Cedar_Rapids.json",
dataType: "jsonp",
success: function (parsed_json) {
alert(parsed_json.location.city);
var location = parsed_json['location']['city'];
var temp_f = parsed_json['current_observation']['temp_f'];
alert("Current temperature in " + location + " is: " + temp_f);
}
});
});
</script>
但它不应该吗?