1
天気の詳細をこのAPIから取得したいのですが、何らかの奇妙な理由で動作しないようです。天気json APIを使用できません
これはmashape APIです。 https://market.mashape.com/fyhao/weather-13
はここで任意の助けが理解されるであろう
function getWeather() {
var lat=null;
var lon=null;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
});
}
var url =
"http://simple-weather.p.mashape.com/weatherdata?lat=" +
lat +
"&lng=" +
lon;
$.ajax({
url: url,
type: "GET",
dataType: "json",
success: function(data) {
$(".location").html(
"<h4>" +
data.query.results.channel.location.city +
", " +
data.query.results.channel.location.country +
"</h4>"
);
$(".weather").html(
"<h4>" + data.query.results.channel.item.condition.text + "</h4>"
);
$(".temperature").html(
"<h4>" + data.query.results.channel.item.condition.temp + "</h4>"
);
},
error: function(err) {
alert(err);
},
beforeSend: function(xhr) {
xhr.setRequestHeader(
"X-Mashape-Authorization",
"MYKEY"
);
}
});
}
$(document).ready(function() {
$(".info").addClass("animated pulse");
getWeather();
});
、私が試したものです。
編集: - 私は、「[オブジェクトのオブジェクト]」により、AJAXでの誤差関数に言う警告エラーを取得しています。ページのポップアップをブロックしたため、最初はエラーが表示されませんでした。物事の
はあなたが取得しているか、エラーを指定してくださいできますか? –
@MannanBahelim私は何も得ていません。 –
私はそれがHTTPレスポンスを返し、あなたはあなたが 'getWeatherを呼び出していることを確認している場合は、多分、「何を取得しない」についてどのようにRUは必ず答え –