날씨 정보를이 API에서 가져오고 싶지만 이상한 이유로 작동하지 않습니다.weather 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();
});
어떤 도움을 이해할 수있을 것이다, 내가 무엇을 시도했다입니다.
편집 - "[object Object]"라는 경고 오류가 발생합니다. 이는 ajax의 오류 기능 때문입니다. 페이지의 팝업을 차단했기 때문에 처음에는 오류가 표시되지 않았습니다. 사물의
당신이지고 어떤 오류 지정하시기 바랍니다 수 있습니까 ?? –
@ManannBahelim 나는 아무 것도 얻지 못하고있다. –
HttpRequester를 사용하여 HTTP 응답을 반환했지만 DOM에이 코드를 삽입해야합니다. –