ほとんどの ajax ソリューションが PHP のようなバックエンド言語を使用する理由について質問したことがあります。
同じドメインポリシーが原因で、Webブラウザーが完全なjavascript/jqueryソリューションを許可しないという事実が原因であると言われました。それでも、以下のコードは問題なく動作します。
<script type="text/javascript">
$(document).ready(function () {
$("#1").click(function () {
$.ajax({
type: "GET",
url: "http://api.wunderground.com/api/ac7e64a2f6e2d440/geolookup/conditions/q/IA/Cedar_Rapids.json",
dataType: "jsonp",
success: function (parsed_json) {
$('div').html("Current temperature in " + parsed_json.current_observation.temp_f);
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>
では、このコードは実行されるべきではないのでしょうか? 理解できません。
ありがとう、ジム