[英]How do I get this JSONP feed to update?
我正在嘗試在網頁的div中用$&ajax顯示JSONP數據。 我希望該數據定期更新。 但是下面的代碼僅顯示一次數據,然后永遠不變。 我應該怎么做才能顯示數據,然后在Feed中的信息發生更改時實際進行更改?
<script type = "text/javascript">
setInterval(function refreshWeather() {
$(function() {
$.ajax({
url : "http://api.wunderground.com/api/mykey/conditions/forecast/q/autoip.json",
dataType : "jsonp",
success : function(parsed_json) {
var temp_f = parsed_json['current_observation']['temp_f'];
var feelslike = parsed_json['current_observation']['feelslike_f'];
var forecast = parsed_json['forecast']['txt_forecast']['date'];
$('#content13').replaceWith(temp_f + " feels like " + feelslike);
}
});
});
}, 90000);
</script>
這似乎可行:
$(function () {
var refreshWeather = function () {
$.ajax({
url: "http://api.wunderground.com/api/mykey/conditions/forecast/q/autoip.json",
dataType: "jsonp",
success: function (parsed_json) {
var temp_f = parsed_json['current_observation']['temp_f'];
var feelslike = parsed_json['current_observation']['feelslike_f'];
var forecast = parsed_json['forecast']['txt_forecast']['date'];
$('#content13').replaceWith(temp_f + " feels like " + feelslike);
}
});
};
refreshWeather();
setInterval(refreshWeather, 90000);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.